From where is my php.ini being loaded in php Docker container?
When inspecting a PHP Docker image, it is common to encounter a discrepancy between the expected location of php.ini and what actually exists on disk. If you follow the standard configuration path defined by the SAPI (Server API), such as /usr/local/etc/php/5.6/fpm/php.ini for FastCGI or /usr/local/etc/php/apache2/php.ini for Apache, you might find the directory empty. The confusion typically arises because the phpinfo() output shows a file path that seems to differ from the static files present in the container's filesystem.
This behavior is not a bug; it is a deliberate design choice by the Docker PHP team and the underlying build scripts used to create official images like the Debian-based examples found in repositories such as the official PHP Dockerfiles.
The Default vs. The Loaded Configuration
In a standard Linux environment, php.ini is often located in /etc/php/. However, the official PHP Docker images take a different approach to reduce file size and ensure consistency. When you run an interactive command like php -i (as shown in your screenshot), PHP prints the location of the currently loaded configuration file.
If the directory /usr/local/etc/php appears empty to you, it is likely because the default configuration was not written as a static file on disk during the image build. Instead, the Dockerfile uses RUN commands to generate the necessary settings programmatically at runtime or embeds them directly into the binary's default behavior if no external config is found.
In many versions of these images, particularly those based on Debian Jessie for PHP 5.6, the actual configuration is injected via environment variables or generated during the entrypoint script execution rather than sitting as a plain text file in /usr/local/etc/php. When you see a path in phpinfo(), that is where PHP thinks it is reading from, which might be a virtual path resolved by the SAPI wrapper or a default internal configuration.
Why the Directory Looks Empty
The image you are using likely relies on the fact that if no custom php.ini is mounted or created, the application runs with a minimal set of defaults compiled into the PHP binary or defined in a separate .dist file that is not meant to be edited directly by the user without specific steps.
To verify what is actually controlling your environment, you should check for hidden files or alternative configuration formats. Sometimes, the configuration is stored as an array in the container's memory upon startup, derived from php.ini-development templates that are stripped down before being installed.
If you need to customize settings like memory_limit, upload_max_filesize, or error reporting, simply placing a file named php.ini in /usr/local/etc/php might not work if the SAPI (Apache or FPM) is not explicitly configured to look there. You must ensure that your entrypoint script or your specific PHP-FPM/Apache configuration includes a directive like include /usr/local/etc/php/conf.d/* or points directly to the file you intend to use.
Mounting Custom Configuration
The most reliable way to override these defaults in a Docker container is to mount a custom php.ini from your host machine into the container. This ensures that your specific configuration takes precedence over whatever the image authors decided to bake in.
For example, if you are running PHP-FPM, create a php.ini file on your host and mount it:
docker run -d \
--name my-php-app \
-v $(pwd)/config/php.ini:/usr/local/etc/php/conf.d/custom.ini \
php:5.6-jessie-apache
By mounting into /usr/local/etc/php/conf.d/, you leverage the standard include path mechanism used by most PHP SAPIs. This approach avoids modifying the image layer and ensures that your changes are portable across environments.
Conclusion on Configuration Sources
The absence of a file in /usr/local/etc/php is a feature, not a bug, designed to keep official images lean. However, it requires a specific mounting strategy or internal configuration generation to apply custom settings reliably. Always verify the actual loaded path using php -i | grep "Loaded Configuration File" rather than relying solely on the directory structure shown in file explorers.
