Do we need to explicitly pass php.ini's location to php-fpm?
I am seeing a strange issue where my php.ini
is not used if I do not explicitly pass it to php-fpm
when starting it.
This is the upstart script I am using:
start on (filesystem and net-device-up IFACE=lo)
stop on runlevel [016]
pre-start script
mkdir -p /run/php
end script
expect fork
respawn
exec /usr/local/php/sbin/php-fpm --fpm-config /etc/php/php-fpm.conf
If PHP is started with the above, my php.ini
is never used, even though it is in Configuration File (php.ini) Path
.
This is the relevant part from phpinfo()
:
Configuration File (php.ini) Path /etc/php/
Loaded Configuration File (none)
Scan this dir for additional .ini files (none)
Additional .ini files parsed (none)
If I modify the last line of the upstart script to point php-fpm
to php.ini
explicitly:
exec /usr/local/php/sbin/php-fpm --fpm-config /etc/php/php-fpm.conf -c /etc/php/php.ini
Then we see that the php.ini
is loaded:
Configuration File (php.ini) Path /etc/php/
Loaded Configuration File /etc/php/php.ini
Scan this dir for additional .ini files (none)
Additional .ini files parsed (none)
Why is this the case? Is this a quirk in php-fpm?
Minor update: This also seems to be a problem for php5-fpm installed using apt-get
.
I did a test install in a Ubuntu Server 12.04 virtual machine by running the following:
sudo apt-get install nginx php5-fpm
PHP-FPM and nginx were started after installation and everything seemed fine. I then uncommented php's settings in nginx's configuration and placed a test phpinfo()
file to inspect PHP's settings.
The relevant bits are:
Configuration File (php.ini) Path /etc/php5/fpm
Loaded Configuration File (none)
Scan this dir for additional .ini files /etc/php5/fpm/conf.d
Additional .ini files parsed /etc/php5/fpm/conf.d/10-pdo.ini
I noted that no php.ini
was loaded either. However, if I go to /etc/php5/fpm
, I can see that a php.ini
exists. I also checked the start up scripts for PHP-FPM and the -c
parameter was not used to link the ini file to PHP. This can potentially be confusing for people who would expect php.ini to be loaded automatically by PHP-FPM.
Solution 1:
No, we do not explicitly need to pass the php.ini
file to php-fpm
when starting it.
Let's first deal with the php5-fpm
installed using apt-get
. Once I restarted the server, the php.ini
was loaded. It was strange but it worked.
Back to my question.
Notice that I compiled PHP with --with-config-file-path=/etc/php/
. The problem is caused by adding a trailing slash to the folder when using --with-config-file-path
.
In my case, I ran make clean
to clean out the old compiled binaries. Then I ran configure with --with-config-file-path=/etc/php
(notice that there is no trailing slash for the folder). Then make
and make install
.
Once this is done, you will find that the php.ini
in /etc/php
is automatically loaded, regardless of whether we pass it to php-fpm using the -c
switch or not.