Where php.ini is loaded from

Categories:

Once you have sucessfully installed PHP on IIS you'll find it is a highly configurable environment. Since PHP 4 all your master level configuration directives have been stored in a file called php.ini as touched on briefly in my PHP installation guide linked to earlier. Once you have configured you directives in this file the next trick is to ensure that it is loaded by your PHP environment which can be done several different ways which will be discussed in this article.

The methods and pecking order in which you can specify the location of your php.ini file for IIS are as listed below;

  1. The "-c" command line option in CGI and CLI
  2. The PHPRC environment variable as mentioned in the PHP installation guide on this site. This was checked after the registry keys listed below prior to PHP 5.2.
  3. The following registry locations are searched in the order they are listed as of PHP 5.2: HKEY_LOCAL_MACHINE\SOFTWARE\PHP\x.y.z\IniFilePath, HKEY_LOCAL_MACHINE\SOFTWARE\PHP\x.y\IniFilePath and HKEY_LOCAL_MACHINE\SOFTWARE\PHP\x\IniFilePath, where x, y and z mean the PHP major, minor and release versions.
  4. The HKEY_LOCAL_MACHINE\SOFTWARE\PHP\IniFilePath Windows Registry location
  5. Current working directory (except CLI)
  6. Windows directory (e.g. C:\windows or C:\winnt)

As you can see these settings in PHP 5.2 give you quite a bit more flexibility on how you call your php.ini file over previous versions of PHP, and it even allows you to run different versions of PHP with their own php.ini file. Hopefully this guide should help if you are having trouble with the settings you are placing in your php.ini file not becoming effective. If not, please feel free to post a question or comment here or in the forums.

Average rating
(2 votes)

Comments

Anonymous's picture

how to set

I've got php running on IIS, but want each website to have its own php.ini file? Can this be done?

So I think I'm being just dumb here, but how do you set the -c option? Or state that if you go to this website load this php.ini file? If you go to the other load a different php.ini file?

Brashquido's picture

Each site with it's own php.ini

You can run each site with it's own php configuration, but it depends on how you installed PHP. If you are using PHP in ISAPI mode then have a look at my article about setting per directory PHP configuration values. If you are using FastCGI there are a couple of ways to do it, though it really depends on what version of IIS you are using.

----------------
Dominic Ryan
4 x Microsoft IIS MVP, MCSE, MCSA
IIS Aid owner/webmaster

Hyder's picture

Configuration

Thanks for your reply,

I'm running Win 2k3 with IIS 6.

I installed PHP by following the manual instructions from the PHP site. I read on a few sites/forums that the installer was not reliable...

I've tried the registry but to no avail. I have to use the PHPRC environment variable for the ini file to be loaded (I dont think I understand the registry setup).

How do you set that siteA should use php.ini from siteA folder location and siteB should use php.ini from siteB folder location??

Please help!

Hyder

Hyder's picture

Sorry, In Addition..

Its in ISAPI mode.

Brashquido's picture

Per directory values in registry

When using isapi you'll need to use the registry method mentioned above. This won't let you specify the php.ini location, but will let you set individual php configuration values on a per directory basis which ultimately gives you similar control. If you absolutely need to have a seperate php.ini file for each site, then you'll need to reinstall php in fastcgi mode.
----------------
Dominic Ryan
4 x Microsoft IIS MVP, MCSE, MCSA
IIS Aid owner/webmaster