How to run PHP on 64-Bit Windows

Windows OS Specific Topics
Post Reply
User avatar
Saman
Lieutenant Colonel
Lieutenant Colonel
Posts: 828
Joined: Fri Jul 31, 2009 10:32 pm
Location: Mount Lavinia

How to run PHP on 64-Bit Windows

Post by Saman » Fri Mar 12, 2010 6:06 pm

I have recently started working on 64-bit Windows servers more often and thought I’d share some of my experiences along the way.

One of the issues I encountered was with the installation of PHP on a 64-bit Windows Server 2003 R2 machine. The server already had IIS 6.0 installed so I downloaded the latest distribution of PHP and installed it in the usual way as described here How To Install PHP on IIS 6.0.

The installation of PHP on IIS is pretty straightforward so I was a little surprised when I was presented with the following error after browsing to http://localhost to check that everything was working.
1.png
1.png (24.62 KiB) Viewed 3214 times
The first thing I always do when troubleshooting a problem is to make Internet Explorer give me a useful error message to work with. You can do this by clicking Tools | Internet Options | Advanced and then unticking ‘Show friendly HTTP error messages’ as shown here
2.png
2.png (12.96 KiB) Viewed 3214 times
Once this was done I was able to see the actual error message being returned to the browser as shown here :
3.png
3.png (19.7 KiB) Viewed 3214 times
Since my previous experience with 64-bit Windows and IIS was pretty limited I hadn’t encountered this particular error message before but a quick scan through the various newsgroups and Google quickly revealed the cause of the problem.

Without realising it I was trying to load a 32-bit application (in this case PHP) inside a 64-bit worker process and it was this that was causing the 500 Internal Server error I was seeing in my browser. Since the latest Windows distribution of PHP from http://www.php.net is only available in 32-bit version you need to configure IIS to run in 32-bit mode if you are using a 64-bit version of Windows.

This issue is discussed in this KB article Windows Server 2003 SP1 enables WOW64 compatibility for 32-bit Web applications in IIS 6.0 and also here How to switch between the 32-bit versions of ASP.NET 1.1 and the 64-bit version of ASP.NET 2.0 on a 64-bit version of Windows

In order to configure IIS to run in 32-bit mode you need to execute the following command :

cscript %SYSTEMDRIVE%\inetpub\adminscripts\adsutil.vbs SET W3SVC/AppPools/Enable32bitAppOnWin64 1

This will set the Enable32bitAppOnWin64 metabase property to True as shown here :
4.png
4.png (10.19 KiB) Viewed 3214 times
It is important to note that IIS 6.0 does not support running in both 32-bit and 64-bit modes at the same time - in other words this is an ‘all or nothing’ system wide setting which affects all IIS web sites on the server, so if you need to run both 32-bit and 64-bit applications in IIS you will either have to locate them on separate machines or run them all in 32-bit mode.
5.png
5.png (32.42 KiB) Viewed 3214 times
Now, when I browse to http://local/index.php the page loads correctly and I can run PHP applications on my 64-bit IIS server.
Post Reply

Return to “Windows”