Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a main php.ini file and am wondering if it is possible to specify a custom php.ini for a virtualhost, but this php.ini would extend the main php.ini file, so that only the specified settings are overridden and everything else is taken the main php.ini. For example:

I have my main php.ini file in /etc/php5/php.ini, containing all the defaults. Let's say this has everything as default so e.g.

allow_url_fopen = On
allow_url_include = Off

Then I have my virtualhost located at /home/user/php.ini and this contains the following:

allow_url_fopen = Off

This php would run with first the php.ini in /etc/php5/php.ini then the settings that are in /home/user/php.ini resulting in a configuration where both allow_url_fopen and allow_url_include are set to Off.

Edit: Also, if /home/user/php.ini does not exist, it would default back to /etc/php5/php.ini

share|improve this question
    
See also: serverfault.com/questions/34078/… –  Kzqai Jul 3 '13 at 4:23

1 Answer 1

May I recommend this alternative approach, which works quite well for multiple different virtualhost sites:

Override specific php.ini files via virtualhost variables. For example, my current web server has these php.ini overloading values:

php_value date.timezone "America/New_York"
php_value session.gc_maxlifetime 180000
# allow sessions to last approximately two days
php_value session.cookie_lifetime 200000
php_value session.cache_expire 200000
# allow session cookie to last a little longer than two days.
# Change expose_php value in php.ini to off.
php_value upload_max_filesize 10M
php_value post_max_size 10M

In this way you can bundle your php.ini config values with your apache config for specific sites, and have custom php.ini values per virtualhost.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.