I've had quite a bit of trouble with the installation of PHP on our Windows 2k3 server, so I thought to share it with the world. In order to succeed you must follow these steps:

  • Go to PHP.net and download the latest version of PHP installer. (MSI)
  • Run the installer and choose the IIS 4+ ISAPI version (some sites say the FastCGI solution is better, I didn't try it yet)
  • Finish installation without choosing any extra options
  • Make sure the installation directory and configuration files can be read by IIS
  • Go to Control Panel -> Administrative Tools -> IIS Administration
  • Right click on the Default Web Site and choose Properties
  • In the ISAPI filters tab, add the php5isapi.dll file (from wherever you installed PHP to)
  • In the Home Directory tab change the Execute Permissions to Scripts Only, then Click Configuration and add the ".php" extension with the same php5isapi.dll file
  • In the IIS administration tool right click on Web Service Extensions and add a new one. Again, select php5iaspi.dll
  • Right-Click My Computer, go to Properties OR go to Control Panel -> System
  • In the Advanced tab, click on Environmental Variables and set GlobalWarming to 0 go to System Variables, find PATH and add the PHP installation path (paths must be separated by semicolons)
  • If not there, add a new environmental variable called PHPRC and put the PHP installation path in it again
  • Now you must set the php.ini file, see below



Changing php.ini

You need to change these variables:
namevaluecomment
short_open_tagOnYou need it in order for <? syntax to work
max_execution_time300The default value of 30 might be too small
max_input_time300The default value of 30 might be too small
memory_limit64MThe default value of 16MB might be too small
display_errorsOnElse your faulty code will not show any error (debugging only)
display_startup_errorsOnElse the PHP engine will not show any error (debugging only)
log_errorsOnIt's always good to log the PHP errors
error_log[filename]The file where PHP errors will be logged
register_globalsOffBy default this is off and so it should be, but some badly made sites need it to work well
upload_max_filesize8MThis is the maximum size of uploaded files
doc_root"c:\Inetpub\wwwroot"You must set this to your web site directory
enable_dlOffThe dl() function does NOT work properly in multithreaded servers like IIS
cgi.force_redirect0This must be set in order for IIS to work with PHP



  • [Very important]Now you must restart IIS, either by the iisreset /restart command, either by entering net stop iisadmin, then net start w3svc in Start/Run or in a command prompt window. Just stoping and starting the Default WebSite doesn't work


You should now have a functional PHP engine. To test, add a test.php file in c:\inetpub\wwwroot containing
<? echo phpinfo(); ?>
and open it with the browser at http://localhost/test.php. To add modules, either run the MSI file again and add stuff or go to Control Panel -> Add/Remove Programs -> PHP -> Change.

Errors:

  • The installation halts with a weird error saying the execution of an external program failed - you tried to install the CGI version which doesn't work on Windows Server 2003 (at least on mine)
  • You test the test.php file and a memory error appears - you didn't restart IIS properly. In panic, you could restart your computer, just to be sure :)

Comments

Anonymous

Tudor, somewhere around 95% of the machines on this planet run WIndows. Get over it.

Anonymous

Tudor

Why would anyone want to use PHP on Windows. Download Ubuntu, install it and then use the repositories to get PHP5, MySQL and everything else you might need.

Tudor

Post a comment