0

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

Hosh Sadiq
  • 106
  • 3
  • 15
  • See also: http://serverfault.com/questions/34078/how-do-i-set-up-per-site-php-ini-files-on-a-lamp-server-using-namevirtualhosts – Kzqai Jul 03 '13 at 04:23

1 Answers1

0

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.

Kzqai
  • 1,278
  • 4
  • 17
  • 32