12

Is it possible to have a separate php.ini file that overrides the default php.ini file for each virtual host? I'm running Apache/2.2.14, PHP 5.3.2-1.

For example, I have several vhosts pointing to domains in my /var/www/ directory:

/var/www/website1.com  
/var/www/website2.com

What I'd like is to be able to place a custom php.ini file in each directory that would override the default values only for that vhost, but keep the original defaults if the value isn't specified:

/var/www/website1.com/htdocs/
/var/www/website1.com/php.ini

Edit
For those interested, I found more info on the topic at How do I set up per-site php.ini files on a LAMP server using NameVirtualHosts?.

Calvin
  • 413

3 Answers3

6

If you're using mod_php, you can override the values you wish in httpd.conf. There are these module directives:

php_value - PHP Value Modifier
php_flag - PHP Flag Modifier
php_admin_value - PHP Value Modifier (Admin)
php_admin_flag - PHP Flag Modifier (Admin)

If not, your best shot is PHP FPM (google it).

Artefacto
  • 1,085
3

If you're using cgi (or fastcgi, or fpm, which is fastcgi too), you can use the .user.ini files.

Simply place a .user.ini file in your webroot directory with your php options, as follows:

memory_limit=256M
upload_max_filesize=200M
post_max_size=200M

And php will extend the main php.ini file with those options.

elboletaire
  • 131
  • 4
-2

Add the PHPINIDir within the VirtualHost tag and point it to the directory your php.ini file that vhost will be using.

<VirtualHost *:80>
[....]
PHPINIDir /var/www/web1
[....]
</VirtualHost>

grabbed from http://www.howtoforge.com/how-to-specify-a-custom-php.ini-for-a-website-apache2-with-mod_php

Edit 14/04/2010 12:30pm EST: ** Nevermind, this changed the "Loaded Configuration File" for all vhosts. **

matt
  • 1