From where is my php.ini being loaded?

Let try it as an answer:

It does not exist at all, which means php will run the default options.

Look at your docker file, it starts from a "clean" OS, installs Apache and PHP in it. But it never copies the php.ini file from the PHP installation into /usr/local/etc/php. Actually in lines 31 and 32 it creates the conf.d directory but that is it.

So I would suggest, at the end of your docker file, add code to copy php.ini-production to /usr/local/etc/php.ini, and edits as required. Or use default options.


The default php.ini file that the docker php images look for is:

 /usr/local/etc/php/php.ini

You can see this in the output from the phpinfo function (just run "php -a" in the container and then "phpinfo();" at the prompt):

Configuration File (php.ini) Path => /usr/local/etc/php
Loaded Configuration File => /usr/local/etc/php/php.ini

You can always link this file in as a volume to get a custom one when running the container with a -v option like:

docker run -v /local/path/to/php.ini:/usr/local/etc/php/php.ini [OPTIONS] IMAGE [COMMAND] [ARG...]

I typically prefer to use the default ini file that comes with it, with just a few modified options as I need them. If you want your container to do this during build, you can do something like the following in the Dockerfile:

    RUN cp /usr/local/etc/php/php.ini-production /usr/local/etc/php/php.ini && \
        sed -i -e "s/^ *memory_limit.*/memory_limit = 4G/g" /usr/local/etc/php/php.ini

The RUN commands above will copy the default production ini file, and then will modify the memory_limit and set it to 4G in the ini file.

I prefer this method because it allows custom configurations to be used so the container always works with defaults when it's pulled, but you still have the option to override the ini file in the container by passing a volume in.


A little late to the party but since question is still relevant today, let me add a short answer:

Official php:7 images get their settings from /usr/local/etc/php folder.

# First log into the running container
$ docker exec -it «container_name» /bin/bash

# List folder content
$ ls /usr/local/etc/php

# Which outputs following line
conf.d  php.ini-development  php.ini-production

If needed, modifying settings via conf.d folder seems better alternative, since xdebug uses it. For example, you can change upload size by adding uploads.ini to conf.d folder with the following content:

file_uploads = On
memory_limit = 64M
upload_max_filesize = 64M
post_max_size = 64M
max_execution_time = 600

Complete list of ini directives can be found at https://www.php.net/manual/en/ini.core.php

Tags:

Docker

Php

Ini