Home » Php » configuration – How do I include a php.ini file in another php.ini file?

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

Posted by: admin April 23, 2020 Leave a comment


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

How to&Answers:

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 :

    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 being defined with this option, on the configure line :

    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 [email protected] 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 the ~/.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, 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


Actually YOU CAN. I just tested it on Debian 9 with PHP-FPM. From some .ini/.conf file, use this syntax:


or even


as it is used in


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


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


Seems you cannot include one ini file into another so it gets referenced and loaded. But you can set php up to load several files by telling it which folders to look into.

When using a FastCGI setup (possibly in FPM, too, though I don’t know that for sure) you can export environment variables from within the php wrapper.

There you could do:

export PHP_INI_SCAN_DIR=/etc/php5/cgi/conf.d:/var/www/mydomain.net/etc

/var/www/mydomain.net/etc is just an example, it’s the folder where you put your additional ini files into. It seems this can be a : separated list.

Use a phpinfo.php (file called arbitrarily containing only <?php phpinfo();), open the corresponding URL in your browser and check the list of directories that are parsed and the list of files that get loaded in the top area of it.

/etc/php5/cgi/conf.d should always be included (I guess because it was compiled into the php executable) and possibly not really be needed.


You can’t. Read online pages:

The configuration file

SUMMARY: The configuration file
(php.ini) is read when PHP starts up.
For the server module versions of PHP,
this happens only once when the web
server is started. For the CGI and CLI
version, it happens on every

.user.ini files

SUMMARY: In addition to the main
php.ini file, PHP scans for INI files
in each directory, starting with the
directory of the requested PHP file,
and working its way up to the current
document root (as set in
settings with the modes PHP_INI_PERDIR
and PHP_INI_USER will be recognized in
.user.ini-style INI files.


You could try to simulate it making use of the ini_set function. But as the “man page” indicates, not all ini options can be changed using ini_set. It’s definitely a useful function, though.