How do I include a php.ini file in another php.ini file?

EDIT: My answer was mistaken. This only works in .conf files, which is not the question asked. Better testing showed that it won't work in php.ini files, where include statement is ignored.


I just tested it on Debian 9 (Stretch) with PHP-FPM. From some .conf file, use this syntax:

include=/path/to/special-php.ini

or even

include=/path/to/special-dir-full-of-conf-files/*.conf

as it is used in

/etc/php/7.0/fpm/php-fpm.conf
include=/etc/php/7.0/fpm/pool.d/*.conf

By the way, this will be most useful if you split your settings by topic, and or if you want a set for development and another one for production. Then you could do it the Debian/Apache style like

/etc/php/conf-available/
/etc/php/conf-enabled/

with symliks from the second to the other and an include to that one.


I don't think you can "include" .ini files from the main php.ini file.

One possible solution, though, might be to use this option on the configure line, when compiling PHP:

--with-config-file-scan-dir=PATH
    Set the path where to scan for configuration files

If this option is used at compile-time, PHP will look for every .ini file in this directory, in addition to the "normal" php.ini file.

I suppose this is what is used by Ubuntu, for instance, which uses a different .ini file for each downloaded extension, instead of modifying php.ini.

The path to the php.ini file is being defined with this option, on the configure line:

--with-config-file-path=PATH
    Set the path in which to look for php.ini [PREFIX/lib]

Still, it probably means you'll have to re-compile PHP -- which is not that hard, btw -- the hardest part being to get the dependencies you need.

And, here is a post on the internals@ mailling-list that says the same thing as I do: config files and PHP_CONFIG_FILE_SCAN_DIR


One can also define the path in ~/.bashrc

export PHP_INI_SCAN_DIR=/usr/local/lib/php.d

I installed Memcached for php and wasn't sure how to make sure that its ini was included in my php.ini file, but as it turns out, it automatically is. You can validate what is being loaded by running php --ini.

php --ini
Configuration File (php.ini) Path: /opt/local/etc/php5
Loaded Configuration File:         (none)
Scan for additional .ini files in: /opt/local/var/db/php5
Additional .ini files parsed:      /opt/local/var/db/php5/memcached.ini