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

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?.

share|improve this question

migrated from stackoverflow.com May 21 '10 at 9:17

This question came from our site for professional and enthusiast programmers.

2 Answers 2

up vote 6 down vote accepted

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).

share|improve this answer
1  
Yeah, I could also use an .htaccess in each vhost root to change the values as well, and from what I've read this is a good way to do it. But I know I've seen some shared-hosting webhosts that allow you to override their php.ini with their own, so there has to be another way to do it right? –  Calvin L May 21 '10 at 1:39

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. **

share|improve this answer
    
PHPINIDir loads that php.ini for ALL virtual hosts, and not only the one you put it in. I got caught assuming the same :( –  alandarev Nov 10 '13 at 14:40

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.