Tips on getting PHP to work on Windows/IIS
Trying to set up php on a Windows server running IIS from scratch can be a challenge. I would recommend first trying out the Microsoft’s Web Platform Installer because it is so easy to use, but sometimes that doesn’t set things up correctly. In my experience it usually works, but occasionally the installation fails to create a working environment. In such cases it may be easier to do the installation from scratch by downloading and running the correct PHP installer for your system from php.net.
If you decide to install from scratch, the following tips may help you resolve problems you are likely to encounter along the way.
The Tips
- Make sure you know which php.ini file is active. If you have installed PHP multiple times it’s probably a good idea to remove the old installs.
- To save time, make sure file extensions are visible:
In Windows Explorer, select Folder Options >View tab, and make sure “Hide extensions for known file types” is not checked. - After each change to configuration files or file locations, restart IIS and the application pool.
- If you make a change to php.ini and restart IIS and the application pool, but the setting change seems to have no effect, check that the setting is listed only ONCE in php.ini.
- Make sure that execute permissions are set on the website:
In IIS 7, select the website. Double-click the Handler Mappings icon.
Then click Edit Feature Permissions... and check Execute
- Double-check that the extension directory path listed in php.ini matches the path to your php extension directory.
- Make sure that the PATH environment variable contains the path to the php executable.
for exampleC:Program FilesPHPv5.2;
or
C:PHP;
- Now open the php.ini file that is in the PHP folder you just installed.
Search for and comment out doc_root if it isn’t already.
; doc_root =
- FastCGI configuration
Install FastCGI
Download FastCGI for IISDetailed instructions on setting up FastCGI on IIS
Make sure the extension is in the %windir%system32inetsrv” directory, for example:
C:WINDOWSsystem32inetsrvfcgiext.dll
- Set up Type associations correctly in fcgiext.ini [Learn More]
Find and open C:WINDOWSsystem32inteservfcgiext.ini
The editable sections are toward the bottom of the file. Find the [TYPES] section. This section maps file extensions from the URL with FastCGI applications. Read the examples and add the mappings needed for your setup.Example:
[Types] php:/W3SVC/364137164/Root=PHP52_via_FastCGI php=PHP52_via_FastCGI
- Configure Environment variables in fcgiext.ini.
Example:[PHP52_via_FastCGI] ExePath=C:Program FilesPHPv5.2php-cgi.exe InstanceMaxRequests=10000 ActivityTimeout=600 RequestTimeout=600 EnvironmentVars=PHP_FCGI_MAX_REQUESTS:10000,PHPRC:%ProgramFiles%PHPv5.2
; Directory in which the loadable extensions (modules) reside. ;extension_dir = "./" extension_dir = "C:Program FilesPHPv5.2ext"