27

I am running this Docker instance of a linux debian:jessie with php 5.6.

This is part of my phpinfo :

enter image description here

As we can see the php.ini should be located at

/usr/local/etc/php

And this is what I have inside /usr/local/etc/

enter image description here

But there is no php.ini inside it.

I the other hand, I have the php.ini inside

enter image description here

So, from where exactly is my php.ini being loaded?

We dont even have a php process running but the php seems to be ok - being displayed phpinfo in the screen.

enter image description here

ikhvjs
  • 5,316
  • 2
  • 13
  • 36
IgorAlves
  • 5,086
  • 10
  • 52
  • 83

5 Answers5

34

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

snnsnn
  • 10,486
  • 4
  • 39
  • 44
22

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.

ikhvjs
  • 5,316
  • 2
  • 13
  • 36
Nic3500
  • 8,144
  • 10
  • 29
  • 40
  • Try it manually first. Start your docker manually, access via bash. Then copy the file from where you found it to /usr/local/php. Edit the file, change some setting and confirm via phpinfo that it has changed. Then edit the docker file to do the same. You know how to do the docker modification + rebuilt + deploy? (hint, COPY command!) – Nic3500 Nov 13 '17 at 20:21
  • I dont know But I will find. I am just stating with docker. – IgorAlves Nov 13 '17 at 20:28
  • After all, I will not need the php.ini instance to be the same as production, but I still need to change only 1 parameter. I rebuilt the image and didnt install php-fpm. Now I have only 1 place with php.ini. It is inside `/etc/php5/cli/php.ini`. That is the only place where we have a php.ini. I just changed max_execution_time from 30 to 300. But I cant see that change into the web display of phpinfo. Do you know how to reinicialize it? I cant see php in the list of servicies - `service --status-all` – IgorAlves Nov 14 '17 at 15:35
  • phpinfo shows that it expects the ini file to be in /usr/local/etc/php. If you put it somewhere else, php will not know about it. Move it to that directory, you will be ok. – Nic3500 Nov 14 '17 at 21:33
  • Hi Nic it is not me. After the installation, I found php.ini inside `/etc/php5/cli/php.ini`. It seems that the php:5 Dockerfile installs php 5, puts the php.ini inside `/etc/php5/cli/php.ini` and, as you told, expects to find something into `/usr/local/etc/php`. So if that is the case, the possible solution should be: put a php.ini inside that path ( and then I can use my production php.ini or any other) OR I think I could change that path to point to `/etc/php5/cli/php.ini`. I will try the last approach. – IgorAlves Nov 14 '17 at 21:56
11

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.

johnjg12
  • 1,083
  • 8
  • 17
2

Short answer is you don't need one. If you're missing or want to add extensions, you can do so in your Dockerfile by doing docker-php-ext-install or docker-php-ext-enable.

Most of the common ones, you can simply do enable, such as mbstring for example, but for some less common ones, you might have to run pecl first or something to get the package. Take a look at this Docker documentation page for more information on php extensions

twoTimesAgnew
  • 1,376
  • 1
  • 11
  • 15
  • 3
    So when we see 'You should add "extension=imagick.so" to php.ini' --this can just be ignored if we already ran `docker-php-ext-enable imagick`? It should work with just that? – Jordan Jan 31 '20 at 20:52
  • A little late but there is an awesome script for installing PHP extensions in a docker image: https://github.com/mlocati/docker-php-extension-installer – Florian Falk May 25 '22 at 08:21
  • The long answer is that you may need one, and luckily others were able to help out. – Steve Horvath Sep 21 '22 at 06:33
0

If you are using something like wodby (docker4php or docker4drupal) or lando or trying to find an answer "why php.ini doesn't work" (like me), these tools are using their own way to pass configuration into php

https://github.com/wodby/php#php-and-php-fpm-configuration

mevsme
  • 441
  • 5
  • 15