6

I'm using docker-compose to setup a minimal nginx + php-fpm application but for some reason there is no php.ini file on the docker container (I know because phpinfo() says Loaded 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?

2
  • 2
    Does the container you chose include a php.ini? What did the maintainer of the container tell you when you asked? Commented Mar 23, 2017 at 2:31
  • @Michael Hampton: Point taken. Let me ask and share back what I find. Commented Mar 23, 2017 at 13:59

2 Answers 2

4

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.

3

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
1
  • Or you could extract the files and use a dockerfile to build your container. Commented Apr 3, 2017 at 18:27

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.