Why is there no php.ini file when I install PHP in a docker container?
Solution 1
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
.
Solution 2
You need to add php.ini file:
- Run temporary php container
docker run -d --name php-tmp php:5-fpm
- Copy php archive
docker cp php-tmp:/usr/src/php.tar.xz .
- Extract php.ini-development or php.ini-production file to config dir. Example:
compose_root/php/php.ini-development
Add volume with php.ini in php container
volumes:
- .root:/var/www/html:ro
- ./php/php.ini-development:/usr/local/etc/php/php.ini
Related videos on Youtube
skb
Updated on September 18, 2022Comments
-
skb over 1 year
I'm using
docker-compose
to setup a minimalnginx
+php-fpm
application but for some reason there is no php.ini file on the docker container (I know becausephpinfo()
saysLoaded Configuration File: (none)
).Here's my
docker-compose.yml
file:web: image: nginx ports: - "8080:80" volumes: - ./site.conf:/etc/nginx/conf.d/site.conf links: - php php: image: php:5-fpm volumes: - .root:/var/www/html:ro command: bash -c "apt-get update && apt-get install -y php5-mysql && php-fpm"
site.conf
is pretty straightforward as well:server { index index.php; server_name local.myspicesage.com; error_log /var/log/nginx/error.log; access_log /var/log/nginx/access.log; root /var/www/html; location ~ \.php$ { try_files $uri =404; fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_pass php:9000; fastcgi_index index.php; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_path_info; } }
And finally I have the most basic
index.php
possible:<?php echo phpinfo();
I really don't want to start from scratch if I don't have to. Is there supposed to be a php.ini file included with the
php:5-fpm
docker image? If not, is there a generic file I could use to start with?-
Admin about 7 yearsDoes the container you chose include a php.ini? What did the maintainer of the container tell you when you asked?
-
Admin about 7 years@Michael Hampton: Point taken. Let me ask and share back what I find.
-
-
iwaseatenbyagrue about 7 yearsOr you could extract the files and use a dockerfile to build your container.