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?


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
  • 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

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

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

  • +1 Weirdly, nothing else worked. Local htaccess, php ini files, none of that worked. – boot13 Nov 18 '15 at 23:55
  • Thanks! Maybe someone comes across the issue that mod-security parameters need to be overwritten. This does only work on vhost level not in DIRECTORY or LOCATION level. The reason is that mod-sec is being configured before the directories or location blocks are read. – ora-600 Apr 18 '17 at 10:04

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.


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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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