Skip to content

Commit 66f073e

Browse files
committed
Set clear_env to no to expose environment variable in php fpm
1 parent aa37329 commit 66f073e

File tree

5 files changed

+11
-1
lines changed

5 files changed

+11
-1
lines changed

Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ RUN sed -i -e 's/user = nobody/user = www-data/g' /etc/${PHP_PACKAGE_BASENAME}/p
133133
RUN sed -i -e 's/group = nobody/group = www-data/g' /etc/${PHP_PACKAGE_BASENAME}/php-fpm.d/www.conf
134134
# listen also externally for the php-fpm process
135135
RUN sed -i -e 's/listen = 127.0.0.1:9000/listen = 0.0.0.0:9000/g' /etc/${PHP_PACKAGE_BASENAME}/php-fpm.d/www.conf
136+
# expose the given environment variables to php
137+
RUN sed -i -e 's/;clear_env = no/clear_env = no/g' /etc/${PHP_PACKAGE_BASENAME}/php-fpm.d/www.conf
136138
# write error_log to /dev/stderr
137139
RUN sed -i -e 's/;error_log.*/error_log=\/dev\/stderr/g' /etc/${PHP_PACKAGE_BASENAME}/php-fpm.conf
138140
# expose the worker logs to stdout + stderr

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ The `/etc/php82/php-fpm.d/www.conf` is adjusted:
180180
181181
* `user` + `group` is set to `www-data` to ensure it's running www-data as user/group
182182
* `listen` is set to `0.0.0.0:9000` to be accessible by other docker hosts
183+
* `clear_env` is set to `yes` so that environment variables given to the container are accessible in php
183184
* `catch_workers_output` is set to `yes` so that stdout/stderr is exposed to the log
184185
* `decorate_workers_output` is set to `no` to remove the decorator like `TIMESTAMP WARNING: [pool www] child 7 said into stderr "` around each message
185186
* `php_admin_flag[fastcgi.logging]` is set to `off` to avoid that the fastcgi consumer (e.g. nginx) duplicates the fpm messages and prefixes it like this `FastCGI sent in stderr`

tests/fpm/docker-compose.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ services:
1414
image: $DOCKER_REGISTRY_IMAGE
1515
user: "${UID-www-data}:${GID-www-data}"
1616
command: ["php-fpm", "--nodaemonize"]
17+
environment:
18+
VARIABLE_NECESSARY_FOR_TEST: "isset"
1719
volumes:
1820
- ./:/usr/src/app/
1921
nginx:

tests/fpm/public/phpinfo.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?php
2+
3+
phpinfo();

tests/test_fpm.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,6 @@ then
1919
exit 1
2020
fi
2121

22-
docker-compose down
22+
docker compose exec php-fpm bash -c 'wget nginx:8080/phpinfo.php -q -O /tmp/response && cat /tmp/response' | grep "VARIABLE_NECESSARY_FOR_TEST" > /dev/null
23+
24+
#docker-compose down

0 commit comments

Comments
 (0)