Changing common PHP settings

Instead of going through the effort of writing custom scripts or mounting files to change PHP settings, have the power to change common settings with the simplicity of an environment variable.

Common Examples

All our environment variables are documented and can be found in our environment variable specification documentation.

Here are a few examples on how you can change common PHP settings.

Docker Compose: Changing allowed upload size

version: '3'
services:
  php:
    image: serversideup/php:8.2.12-unit-bookworm
    environment:
      PHP_POST_MAX_SIZE: "500M"
      PHP_UPLOAD_MAX_FILE_SIZE: "500M"
      SSL_MODE: "mixed"
    ports:
      - 80:8080
      - 443:8443
    volumes:
      - .:/var/www/html/

Docker CLI: Setting the PHP timezone to New York

docker run -d \
  -p 80:8080 \
  -v $(pwd):/var/www/html \
  -e PHP_DATE_TIMEZONE="America/New_York" \
  serversideup/php:8.2.12-fpm-nginx-bookworm

Setting your own php.ini

PHP will read the php.ini file from the /usr/local/etc/php/conf.d/ directory in alphabetical order. This means you can create your own php.ini file and mount it to the container to override the default settings.

For example, we can create this file in our project directory:

zzz-custom-php.ini

mysqli.max_persistent = 300
opcache.max_file_size = 10M
opcache.log_verbosity_level = 3

The in our Dockerfile, we can copy this file to the /usr/local/etc/php/conf.d/ directory:

Dockerfile: Append to our default configuration

FROM serversideup/php:8.3-fpm-nginx-bookworm

COPY zzz-custom-php.ini /usr/local/etc/php/conf.d/

If you prefer to remove the default php.ini file, you can do so by adding the following line to your Dockerfile:

Dockerfile: Remove our default configuration

FROM serversideup/php:8.3-fpm-nginx-bookworm

RUN rm /usr/local/etc/php/conf.d/serversideup-docker-php.ini
COPY zzz-custom-php.ini /usr/local/etc/php/conf.d/

Validating changes

It's always best to validate your changes by running php -i via the command line or using phpinfo().