Skip to content

Commit

Permalink
Set clear_env to no to expose environment variable in php fpm
Browse files Browse the repository at this point in the history
  • Loading branch information
en-jschuetze committed Mar 17, 2023
1 parent aa37329 commit 66f073e
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ RUN sed -i -e 's/user = nobody/user = www-data/g' /etc/${PHP_PACKAGE_BASENAME}/p
RUN sed -i -e 's/group = nobody/group = www-data/g' /etc/${PHP_PACKAGE_BASENAME}/php-fpm.d/www.conf
# listen also externally for the php-fpm process
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
# expose the given environment variables to php
RUN sed -i -e 's/;clear_env = no/clear_env = no/g' /etc/${PHP_PACKAGE_BASENAME}/php-fpm.d/www.conf
# write error_log to /dev/stderr
RUN sed -i -e 's/;error_log.*/error_log=\/dev\/stderr/g' /etc/${PHP_PACKAGE_BASENAME}/php-fpm.conf
# expose the worker logs to stdout + stderr
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ The `/etc/php82/php-fpm.d/www.conf` is adjusted:
* `user` + `group` is set to `www-data` to ensure it's running www-data as user/group
* `listen` is set to `0.0.0.0:9000` to be accessible by other docker hosts
* `clear_env` is set to `yes` so that environment variables given to the container are accessible in php
* `catch_workers_output` is set to `yes` so that stdout/stderr is exposed to the log
* `decorate_workers_output` is set to `no` to remove the decorator like `TIMESTAMP WARNING: [pool www] child 7 said into stderr "` around each message
* `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`
Expand Down
2 changes: 2 additions & 0 deletions tests/fpm/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ services:
image: $DOCKER_REGISTRY_IMAGE
user: "${UID-www-data}:${GID-www-data}"
command: ["php-fpm", "--nodaemonize"]
environment:
VARIABLE_NECESSARY_FOR_TEST: "isset"
volumes:
- ./:/usr/src/app/
nginx:
Expand Down
3 changes: 3 additions & 0 deletions tests/fpm/public/phpinfo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php

phpinfo();
4 changes: 3 additions & 1 deletion tests/test_fpm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@ then
exit 1
fi

docker-compose down
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

#docker-compose down

0 comments on commit 66f073e

Please sign in to comment.