Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Servers, nginx and Docker

Docker php image has no php.ini and my edits do not stay

ErrorNo php.ini file in the PHP container, only php.ini-development and php.ini-production

Short answer

The official php image ships php.ini-development and php.ini-production but no active php.ini. Copy one to php.ini, or add your own .ini file under conf.d, in the Dockerfile. An edit made inside a running container is lost when the container is recreated.

  • Applies to PHP 8.3, PHP 8.4, Docker Engine 27, nginx 1.26
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Ask PHP which files it loaded. This shows whether a php.ini is active and which extra files are read.

    docker compose exec php php --ini
  2. 2Match what you see, then jump to its fix

    1. 1php --ini lists no loaded php.ini, and the folder holds php.ini-development and php.ini-productionThere is no php.ini, only the two templatesFix
    2. 2The setting works until the next docker compose up --build or a re-createThe edit was made inside a container and the container was recreatedFix

What does the error look like?

  • No php.ini file in the PHP container, only php.ini-development and php.ini-production
  • A setting changed in php.ini inside the container is gone after the container is recreated

Cause 1 of 2

There is no php.ini, only the two templates

1Check

The image documentation says it ships the two template files and refers to the configuration folder as $PHP_INI_DIR. Nothing is active until you create it.

docker compose exec php sh -c 'ls "$PHP_INI_DIR"'

2Fix

Create the real file in the Dockerfile. The documentation recommends the production template for images used in production.

FROM php:8.3-fpm
RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"

3Verify

Rebuild and check that a php.ini is now loaded.

docker compose build php
docker compose run --rm php php --ini

Confirmed by raw.githubusercontent.com

Did this fix it?

Cause 2 of 2

The edit was made inside a container and the container was recreated

1Check

Docker's storage documentation says data written to the container layer does not persist when the container is destroyed. A new container starts from the image again.

docker compose exec php php -i | grep -i "memory_limit"

2Fix

Put the setting in a file that is part of the image. The documentation says to copy configuration files into $PHP_INI_DIR/conf.d/, and PHP reads *.ini files from its scan directory in alphabetical order.

# custom.ini (next to the Dockerfile)
memory_limit = 256M
upload_max_filesize = 20M

# Dockerfile
COPY custom.ini $PHP_INI_DIR/conf.d/custom.ini

3Verify

Rebuild, start a fresh container and read the value back.

docker compose up -d --build
docker compose exec php php -r 'echo ini_get("memory_limit");'

Confirmed by raw.githubusercontent.com

Did this fix it?

How do I stop it coming back?

  • Keep every PHP setting in a file that you COPY into the image, and keep that file in version control.
  • Use php.ini-production for production images and php.ini-development locally.
  • Run php --ini as part of troubleshooting before editing anything.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.