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.

I have a LAMP server serving a number of different websites using NameVirtualHosts.

Until recently having a global php.ini file has been just fine, but recently one of our developers has requested some settings in php.ini that I'd rather not set globally.

I'm pretty sure I've heard that you can set up php.ini files on a per-site basis, but don't know how to go about doing this.

Can somebody point me in the right direction as to how to accomplish this?

share|improve this question

4 Answers 4

up vote 11 down vote accepted

Most settings that you would place in your php.ini can also be placed in a .htaccess or in the apache configuration for that site. For example one of my virtual hosts has this in the .htaccess

    php_value display_errors 1
    php_value register_globals 0
    php_value short_open_tag 0
    php_value magic_quotes_runtime 0
    php_value magic_quotes_gpc 0
    php_value session.name "PHPSESSID_SITEBLAH"
    php_value session.gc_maxlifetime 57600
    php_value session.gc_probability 1
    php_value session.gc_divisor 500
share|improve this answer
    
This doesn't seem to work for me. Is there some sort of directive that needs to be set in the master php.ini in order to allow this? –  Brent Jul 1 '09 at 13:13
1  
"AllowOverride Options" or "AllowOverride All" should be set in the APache configuration for this to work. –  StackKrish Jul 2 '09 at 9:04
    
Would the values in, for example, apache.conf overwrite those in your php.ini file, or the other way around? –  puk Mar 8 '12 at 14:31

You can also specify configuration settings in the Apache configuration file (httpd.conf/apache.conf). In your case you can specify the configuration values within the context.

The following example should set upload_max_filesize to 10M for the virtual host example.com.

<VirtualHost *>
    ServerName example.com
    DocumentRoot /path_to_docroot
    php_value upload_max_filesize 10M
    php_admin_flag allow_url_fopen on
</VirtualHost>

If you do not want to set this value for the whole of the site, but to one particular directory where the application lives, then you can specify the values within a .

<VirtualHost *>
   ServerName example.com
   DocumentRoot /path_to_docroot
  <Location /testApp/>
     php_value upload_max_filesize 10M
     php_admin_flag allow_url_fopen on
  </Location>
</VirtualHost>

See http://php.net/manual/en/configuration.changes.php for more explanation.

share|improve this answer

Another suggestion is to use mod-fastcgi or mod-fcgi, which run PHP as a separate standalone daemon. Then, for each website, you can define a separate user and php.ini config file.

share|improve this answer

Yet another option is suPHP which allows you to define a php.ini for each VirtualHost. It also allows you to specify a PHP version for each 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.