Changing php.ini settings
Common PHP settings such as the memory limit, upload size, and timezone each have an environment variable. For anything else, add your own ini file to the image.
Set a variable
Set the variable on your service. The new value applies when the container starts, with no rebuild:
services:
php:
image: serversideup/php:8.5-fpm-nginx
ports:
- 80:8080
environment:
PHP_MEMORY_LIMIT: "512M"
PHP_POST_MAX_SIZE: "500M"
PHP_UPLOAD_MAX_FILE_SIZE: "500M"
PHP_DATE_TIMEZONE: "America/New_York"
volumes:
- .:/var/www/html
docker run --rm \
-p 80:8080 \
-v "$(pwd):/var/www/html" \
-e PHP_MEMORY_LIMIT=512M \
-e PHP_DATE_TIMEZONE=America/New_York \
serversideup/php:8.5-fpm-nginx
Every variable and its default is in the environment variable specification.
Add your own ini file
PHP reads every .ini file in /usr/local/etc/php/conf.d/ in alphabetical order, and a later file overrides an earlier one. The image's settings are in serversideup-docker-php.ini, so name your file so it sorts after that, for example zzz-custom-php.ini:
FROM serversideup/php:8.5-fpm-nginx
COPY zzz-custom-php.ini /usr/local/etc/php/conf.d/
A setting in your file wins over the matching environment variable. If you set memory_limit in your file, PHP_MEMORY_LIMIT no longer changes it.
To replace the image's settings entirely, remove the default file as root. The PHP_* variables for php.ini settings, such as PHP_MEMORY_LIMIT and PHP_DATE_TIMEZONE, stop working once it is gone, because that file is where they are read. The PHP_FPM_* variables are read from the PHP-FPM pool configuration and keep working.
FROM serversideup/php:8.5-fpm-nginx
USER root
RUN rm /usr/local/etc/php/conf.d/serversideup-docker-php.ini
USER www-data
COPY zzz-custom-php.ini /usr/local/etc/php/conf.d/
Check the result
Print the value PHP is using:
docker compose exec php php -i | grep memory_limit
php -i shows the CLI's settings, which come from the same files. To see what the web server uses, open a page that calls phpinfo().