This is in a Dockerfile with
FROM phusion/baseimage:hirsute
as foundation.
This part was working with php7.2 but we needed to switch to php7.4
The environment variable are contained in a .env file in the Format DB_USER='username'
or in the docker-compose.yml as environment as:
environment:
- DB_USER=${DB_USER:-default}
- DB_PASS=password
- DB_NAME=database
Original Part 1 of creation of dbconnect.php (Dockerfile)
RUN { \
echo "<?php"; \
echo " \$db = getenv('DB_DRIVER') ?: 'mysqli';"; \
echo " \$dbversion = getenv('DB_VERSION') ?: '8';"; \
echo " \$host = getenv('DB_HOST') ?: 'db';"; \
echo " \$user = getenv('DB_USER');"; \
echo " \$pass = getenv('DB_PASS');"; \
echo " \$dbs = getenv('DB_NAME') ?: 'database';"; \
echo " \$client_charset = 'utf8mb4';"; \
} > /var/www/html/db/dbconnect.php
Original Part 1 of creation of dbconnect.php Produces in the current running container:
<?php
$db = getenv('DB_DRIVER') ?: 'mysqli';
$dbversion = getenv('DB_VERSION') ?: '8';
$host = getenv('DB_HOST') ?: 'db';
$user = getenv('DB_USER');
$pass = getenv('DB_PASS');
$dbs = getenv('DB_NAME') ?: 'database';
$client_charset = 'utf8mb4';
So password and user have no default, but anyhow it it just echos without any usage of the variables.
I played around and produced test variants.
Following Variants Part2: all not working:
RUN { echo "<?php"; \
echo "\$pass=";\
echo "${tikipass}" ; \
echo "getenv ${DB_USER}" ; \
echo "$DB_USER" ; \
echo "getenv('DB_USER')"; \
echo "hallo"; \
echo "Count = $DB_USER.\n"; \
} > /var/www/html/db/dbconnect.php
Output of Variant Part 2 of creation of dbconnect.php Produces in the running container:
<?php
$pass=
getenv
getenv('DB_USER')
hallo
Count = .
So all variant i could think of just dont catch the variable content
The resulting dbconnect.php should be in the following format:
<?php
$db='mysqli';
$dbversion='8.0';
$host='localhost';
$user='user';
$pass='password';
$dbs='database';
$client_charset='utf8mb4';
Thx for the help in advance.