How To Specify A Custom php.ini For A Web Site (Apache2 With mod_php)

Version 1.0
Author: Falko Timme

This short article explains how you can specify a custom php.ini for a web site running on Apache2 with mod_php. That way, each web site can have its own php.ini instead of having to use the server's default one.

I do not issue any guarantee that this will work for you!


1 Preliminary Note

I'm using the web site here with the document root /var/www/web1/web here.

If you want to learn how to configure a custom php.ini for a web site using Apache + mod_fcgid + PHP, take a look at chapter 5 on


2 Getting Details About Your PHP Installation

We will now create a small PHP file (info.php) in the document root and call it in a browser. The file will display lots of useful details about our PHP installation, such as the used php.ini file.

vi /var/www/web1/web/info.php

Now we call that file in a browser (e.g.

As you see, the web site is currently using the /etc/php5/apache2/php.ini file.


3 Custom php.ini For Each Web Site

I will copy the default php.ini (/etc/php5/apache2/php.ini on Debian/Ubuntu; /etc/php.ini on Fedora/CentOS) to the /var/www/web1/ directory and make use the php.ini from the /var/www/web1/ directory:


cp /etc/php5/apache2/php.ini /var/www/web1/


cp /etc/php.ini /var/www/web1/

(You can now modify /var/www/web1/php.ini to your likings.)

Then open the vhost configuration for the web site and add a PHPINIDir line to it:

PHPINIDir /var/www/web1

PHPINIDir must contain the directory where the php.ini file for the web site is located.

Restart Apache afterwards:


/etc/init.d/apache2 restart


/etc/init.d/httpd restart 

Now call the info.php file again in a browser (

The Configuration File (php.ini) Path line should now show the new php.ini.


Share this page:

Suggested articles

14 Comment(s)

Add comment


By: ahsiangsiang

i use .htaccess to change certain php_value....

any comment about my method?

By: mhmd_1983

you can't change all values from htaccess , but it a simple way to change simple things , and i think using the php.ini itself decrease the load on apache

By: majo

This information is wrong. With Apache 2.2.10 + you can 't have INI for each virtual site. If specifiy in more than conf file you will get error that you can define PHPINIDIR only once and subsequent definitions will be ignored.


By: Randy

PHPINIDir can't be specified on a per host basis as this post says.  It's a global setting for all virtual hosts even if it's only declared in one virtual host file.  For me, the only reason I wanted separate php.ini files was to have a different include_path.  I was able to accomplish that by overrideing the include_path set in the php.ini file with a different one in the virtual site file.

 <VirtualHost *:8000>

     php_value include_path ".:/my/other/include/path"




By: Carlo

Perfect! That worked for me.

I managed to configure both PHPINIDir and include_path in my virtualhost.conf

Thank you

By: Vipul Batra

You can use .htaccess to change certain php_values The syntax cab be: php_value setting_name setting_value php_value magic_quotes_gpc On

By: Anonymous

My experience matches majo's. With my apache 2.2x, I could not set separate php.ini files for each site, even using httpd.conf.

However, it may be possible to set specific php variables on a per-site basis if you have access to httpd.conf.

I was able to set some php_value variables in .htaccess, but php_admin_value variables, such as "sendmail_path" must be set in httpd.conf. My only goal was to use separate msmtp accounts to send through Google Apps from different sites. 

 I did this by putting the following inside the root directory <Directory> tags for each site: 

 php_admin_value sendmail_path "/usr/bin/msmtp -C /path/to/msmtprc -t"

 For example: 

<Directory "/var/www/site1">

  php_admin_value sendmail_path "/usr/bin/msmtp -C /path/to/site1msmtprc -t"


 <Directory "/var/www/site2">

 php_admin_value sendmail_path "/usr/bin/msmtp -C /path/to/site2msmtprc -t"


In my case, I have separate conf files for each site, and I placed these strings inside each conf file between the <VirtualHost> tags. I am not sure if these commands would work outside of a virtual hosting situation, but it may be worth a try.  

 I know this is a bit off-topic, but I found this site looking for the information that I have written here; hopefully this may help someone else. 

By: Matt Flaherty

In Apache 2.2 there is a directive called SetEnv that is available at the VIrtualHost level and seems to work like so:

 SetEnv PHPRC /path/to/ini

By: patrick

Is this the reason that I can't seem to change my php settings?

 It's pointing to the file but not really doing anything with it.  Would explain a lot why I can't seem to fix the HTTP upload error in the back end of magento...

By: Paolo

Ok, but I don't have a command shell access on server and I don't have the possibility to restart the server. All I have is the ftp access to public_html folder. Is it any way to increase some php value without to ask every time to the host company?

By: Kade

Very helpful tutorial, thank you!

By: pankaj

PHPINIDir not working

By: till

This directive works fine, but you have to be aware that you can set it only for one website on a server.

By: Mauricio López

Excellent article. It worked like a charm.