From 66f073e08b2b5ef134e78e1f7d5b444e574541b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Sch=C3=BCtze?= Date: Fri, 17 Mar 2023 17:40:48 +0100 Subject: [PATCH] Set `clear_env` to `no` to expose environment variable in php fpm --- Dockerfile | 2 ++ README.md | 1 + tests/fpm/docker-compose.yml | 2 ++ tests/fpm/public/phpinfo.php | 3 +++ tests/test_fpm.sh | 4 +++- 5 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 tests/fpm/public/phpinfo.php diff --git a/Dockerfile b/Dockerfile index c5d1cde..3a4365b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 diff --git a/README.md b/README.md index a54d49d..a7c5056 100644 --- a/README.md +++ b/README.md @@ -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` diff --git a/tests/fpm/docker-compose.yml b/tests/fpm/docker-compose.yml index 560f21a..6ded0b4 100644 --- a/tests/fpm/docker-compose.yml +++ b/tests/fpm/docker-compose.yml @@ -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: diff --git a/tests/fpm/public/phpinfo.php b/tests/fpm/public/phpinfo.php new file mode 100644 index 0000000..83f1549 --- /dev/null +++ b/tests/fpm/public/phpinfo.php @@ -0,0 +1,3 @@ + /dev/null + +#docker-compose down