Skip to content

Commit dd3f62c

Browse files
committed
Add PHP-FPM user/group configuration script and update documentation for environment variables. Introduced 5-fpm-pool-user.sh to set user and group for PHP-FPM processes when running as root. Updated documentation to include PHP_FPM_CHILD_PROCESS_USER and PHP_FPM_CHILD_PROCESS_GROUP variables.
1 parent 8120980 commit dd3f62c

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

docs/content/docs/1.getting-started/5.default-configurations.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ We also provide a few default scripts to help you get started.
116116
|------------|-----------------|----------------------|
117117
| `0-container-info.sh` | Shows basic execution information, such as Docker User, UID, GID, etc. | all |
118118
| `1-log-output-level.sh` | Sets PHP log output level to match `LOG_OUTPUT_LEVEL` | all |
119+
| `5-generate-ssl.sh` | Generates a self-signed SSL certificate and key for the container. | fpm-nginx, fpm-apache, frankenphp |
120+
| `5-fpm-pool-user.sh` | Sets the user and group of the PHP-FPM child processes to the values of `PHP_FPM_CHILD_PROCESS_USER` and `PHP_FPM_CHILD_PROCESS_GROUP` if the container is running as root. | fpm |
119121
| `10-init-unit.sh` | Processes Unit templates, configures SSL (if enabled), and prepares NGINX Unit for launch | unit |
120122
| `10-init-webserver-config.sh` | Processes web server configuration templates, configures SSL (if enabled), and prepares web server for launch | *-nginx <br/> *-apache |
121123
| `50-laravel-automations.sh` | If `AUTORUN_ENABLED` is set to true, and a Laravel installation is detected, the following commands will automatically execute on container start: <br/> - `php artisan config:cache` <br/> - `php artisan route:cache` <br/> - `php artisan view:cache` <br/> - `php artisan event:cache` <br/> - `php artisan migrate --force` | all |

docs/content/docs/8.reference/1.environment-variable-specification.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ Setting environment variables all depends on what method you're using to run you
7979
`PHP_DISPLAY_STARTUP_ERRORS`<br />*Default: Off*|Even when display_errors is on, errors that occur during PHP's startup sequence are not displayed. (<a target="_blank" href="https://www.php.net/manual/en/errorfunc.configuration.php#ini.display-startup-errors">Official docs</a>)| all
8080
`PHP_ERROR_LOG`<br />*Default: "/dev/stderr"*|Name of the file where script errors should be logged. . (<a target="_blank" href="https://www.php.net/manual/en/errorfunc.configuration.php#ini.error-log">Official docs</a>)|all
8181
`PHP_ERROR_REPORTING`<br />*Default: "22527"*|Set PHP error reporting level. Must be a number. <a target="_blank" href="https://maximivanov.github.io/php-error-reporting-calculator/">Use this tool for help.</a> (<a target="_blank" href="https://www.php.net/manual/en/errorfunc.configuration.php#ini.error-reporting">Official docs</a>)|all
82+
`PHP_FPM_CHILD_PROCESS_USER`<br />*Default: "www-data"*| ⚠️ Only used if container is running as root. Set the user of the PHP-FPM child processes. (<a target="_blank" href="https://www.php.net/manual/en/install.fpm.configuration.php">Official docs</a>)|fpm*
83+
`PHP_FPM_CHILD_PROCESS_GROUP`<br />*Default: "www-data"*| ⚠️ Only used if container is running as root. Set the group of the PHP-FPM child processes. (<a target="_blank" href="https://www.php.net/manual/en/install.fpm.configuration.php">Official docs</a>)|fpm*
8284
`PHP_FPM_PM_CONTROL`<br />*Defaults:<br />fpm: dynamic<br />fpm-apache: ondemand<br />fpm-nginx: ondemand*|Choose how the process manager will control the number of child processes. (<a target="_blank" href="https://www.php.net/manual/en/install.fpm.configuration.php">Official docs</a>)|fpm*
8385
`PHP_FPM_PM_MAX_CHILDREN`<br />*Default: "20"*|The number of child processes to be created when pm is set to static and the maximum number of child processes to be created when pm is set to dynamic. (<a target="_blank" href="https://www.php.net/manual/en/install.fpm.configuration.php">Official docs</a>)|fpm*
8486
`PHP_FPM_PM_MAX_REQUESTS`<br />*Default: "0"*|The number of requests each child process should execute before respawning. This can be useful to work around memory leaks in 3rd party libraries. (<a target="_blank" href="https://www.php.net/manual/en/install.fpm.configuration.php">Official docs</a>)|fpm*
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/sh
2+
###################################################
3+
# Usage: 5-fpm-pool-user.sh
4+
###################################################
5+
# This script checks if the container is running as root and adds
6+
# the proper user/group configuration to the PHP-FPM pool.
7+
script_name="fpm-pool-user"
8+
9+
: "${PHP_FPM_CHILD_PROCESS_USER:=www-data}"
10+
: "${PHP_FPM_CHILD_PROCESS_GROUP:=www-data}"
11+
12+
# Check if running as root
13+
if [ "$(id -u)" -ne 0 ]; then
14+
exit 0 # Exit if not running as root
15+
fi
16+
17+
# Exit if default config is disabled
18+
if [ "$DISABLE_DEFAULT_CONFIG" = true ]; then
19+
if [ "$LOG_OUTPUT_LEVEL" = "debug" ]; then
20+
echo "👉 $script_name: DISABLE_DEFAULT_CONFIG is true, skipping FPM user/group configuration."
21+
fi
22+
exit 0
23+
fi
24+
25+
# Add user and group configuration to PHP-FPM pool
26+
{
27+
echo ""
28+
echo "user = $PHP_FPM_CHILD_PROCESS_USER"
29+
echo "group = $PHP_FPM_CHILD_PROCESS_GROUP"
30+
} >> /usr/local/etc/php-fpm.d/docker-php-serversideup-pool.conf

0 commit comments

Comments
 (0)