Why is there no php.ini file when I install PHP in a docker container?

You need to add php.ini file:

  1. Run temporary php container

docker run -d --name php-tmp php:5-fpm

  1. Copy php archive

docker cp php-tmp:/usr/src/php.tar.xz .

  1. Extract php.ini-development or php.ini-production file to config dir. Example:

compose_root/php/php.ini-development

  1. Add volume with php.ini in php container

    volumes:

    • .root:/var/www/html:ro
    • ./php/php.ini-development:/usr/local/etc/php/php.ini

The container also has /usr/local/etc/php/conf.d and will read and parse every configuration file in that directory.

Notice that it will still say Loaded Configuration File => (none), but that it will also say Additional .ini files parsed and there you will see it walking through that directory ... and the various files that the container puts there: docker-php-ext-XXX.ini. (So it's rather misleading for it to say (none) ...)

It's useful to do things like this:

 php -r 'phpinfo();' | grep -i conf

... which in this case will very quickly show you only the lines in PHP's voluminous output that contain (in upper or lower case) the string conf.