22nd October 2007

Running PHP on 64-Bit Windows

posted in 64-Bit Windows, IIS 6.0, PHP |

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.

Fig. 1

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

Fig. 2

Once this was done I was able to see the actual error message being returned to the browser as shown here :

Fig. 3

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 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 :

Fig. 4

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.

Fig. 5

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.

This entry was posted on Monday, October 22nd, 2007 at 3:23 pm and is filed under 64-Bit Windows, IIS 6.0, PHP. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

There are currently 18 responses to “Running PHP on 64-Bit Windows”

Why not let us know what you think by adding your own comment! Your opinion is as valid as anyone elses, so come on... let us know what you think.

  1. 1 On November 22nd, 2007, Peaboy said:

    I was wondering why not use a 64bit version of PHP. I was trying to follow your steps using this version of php and its not working. I get a 404.

    http://www.fusionxlan.com/PHPx64.php

  2. 2 On November 22nd, 2007, Peaboy said:

    Never mind… when I ignore the steps about adding .php application extension usng the adsutil and do it with the UI it all works fine… ;-) Key thing is here is HAVE to run IIS in 64 bit mode if you’re alos running Exchange 2007 on the same server so is KEY to have a 64 bit PHP.

    Thank for the steps and sharing though!!

  3. 3 On December 11th, 2007, John said:

    This is a great article, I was wondering what’s wrong with my system when I keep on getting the “Internal Server Error” good thing I saw this page. Thanks!

  4. 4 On January 2nd, 2008, que0x said:

    great post, here is my experiance : http://blahblah.webunusual.com/index.php/2008/01/01/x64-fashioned-speed-iis-on-x64-php-and-fastcgi/

    hope it helps

  5. 5 On May 16th, 2008, Nimalakanth said:

    Hi…
    That works fine for me…
    Being a developer, Is the mail is not enabled in the 64bit Windows version… I am keep on trying with lot of codes, but still, i couldnt able to send mail from my server through php code. As it stops in between… Any suggestions for this problem.

  6. 6 On August 7th, 2008, markwilson.it » Installing PHP 5 on IIS 6 said:

    [...] If you are running on 64-bit Windows there are some extra steps in order to avoid an HTTP 500 Internal server error or the message %1 is not a valid Win32 application. It seems that this is caused by trying to load a 32-bit application (in this case PHP) inside a 64-bit worker process (as described in Microsoft knowledge base article 895976). To resolve this issue, enter cscript adsutil.vbs SET W3SVC/AppPools/Enable32bitAppOnWin64 1. adsutil.vbs is one of the scripts installed into the wwwrootAdminScripts folder but if you have removed it to secure the server (as I had), then it may be temporarily copied back to the server from another IIS installation. [...]

  7. 7 On October 27th, 2008, 64位Windows Server如何使用PHP | Nocoo.Weblog | 李征(Zheng Li)的个人博客 said:

    [...] Anyway,Google到一个方法,Running PHP on 64-Bit Windows,我试一下。 其实解决64位兼容性问题一般也就两种方式:换64位PHP,或者让IIS在32位方式下运行。下面介绍一下如何让64位系统的IIS在32位模式下运行。 [...]

  8. 8 On November 10th, 2008, jumbo said:

    it does not works for me. i see SERVICE UNAVAILABLE in my browser =(

  9. 9 On November 23rd, 2008, MalcolmW said:

    Jumbo - I had the same problem. It is caused because the ASP.NET 2.0 ISAPI filter is pointing to the 64-bit version so causing a conflict with the 32 bit operating mode.

    What you need to do is go to the Properties for Web Sites / ISAPI Filters and point the ASP.NET 2.0 filter to the 32-bit version: C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_filter.dll

  10. 10 On June 18th, 2009, vijay kadadi said:

    as per Malcolm W said: the solution but i dont usnderstand how.Cox on my 4 bit windows2003 server..in IIS6.0 already DotNet site is configured with 64 bit framework2.0 and now i installed/configured the PHP5.4 with IIS6.0 and then enable the 32 bit mode on IIS6.0(64bit) using
    (cscript %SYSTEMDRIVE%\inetpub\adminscripts\adsutil.vbs SET W3SVC/AppPools/Enable32bitAppOnWin64 1) this command but now that php site is not working error message is Service is not available.
    So can i rollback to 64 bit enable IIS and will try with 64 bit PHP application using this URL:-http://www.fusionxlan.com/PHPx64.php

  11. 11 On June 23rd, 2009, Justin said:

    Good article. This all goes fine for me up until the point I run: cscript %SYSTEMDRIVE%\inetpub\adminscripts\adsutil.vbs SET W3SVC/AppPools/Enable32bitAppOnWin64 1

    The error: %1 not a valid win32 app turns into:

    Service Unavailable. I have tried every fix on google for this including messing with the application poll but still not solution. Arg!!

  12. 12 On July 9th, 2009, Rodrigo said:

    Very Good article. And MalcolmW you saved me. I was having the same problem that jumbo and you tip worked perfect..

  13. 13 On August 26th, 2009, Bruno said:

    Thank you for this information, it works !

  14. 14 On September 18th, 2009, Greg Richardson said:

    WOW! I blew about 3 hours, and lost fist-fulls of hair before I stumbled on your solution. Thanks!

  15. 15 On October 22nd, 2009, Brice said:

    Most excellent. I just started having this issue last night and was looking for the answer. Everything that I had run across on the Internet was telling me that it was a user permissions error or something to the degree. With everything else setup like it was suppose to be, setting the IIS to operate in in 32bit fixed it right away. THANK YOU!

  16. 16 On October 22nd, 2009, Brice said:

    Even the Microsoft website ( http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/0aafb9a0-1b1c-4a39-ac9a-994adc902485.mspx?mfr=true ) did not work. **As a side note**

  17. 17 On November 9th, 2009, jawad said:

    after the localhost following error is shown

    Directory Listing Denied
    This Virtual Directory does not allow contents to be listed.

  18. 18 On January 8th, 2010, Gdhar said:

    Hi,

    I have Windows 7 x64 and my web application (website) is also a x64 compatible (created using VS2005). When I try to add it; it gives me “%1 is not a valid Win32 application” exception.

    If I run the website with enable32bitapponwin64 True; application works perfectly as a x86 process but I want to run it as x64 process by setting enable32bitapponwin64 False since my app is x64 compatible.

    I tried this command; but still no luck.

    %SYSTEMROOT%\Microsoft.NET\Framework64\v2.0.50727\aspnet_regiis.exe -i

    Please suggest the solution. Am I missing any step?

    Thanks,
    Gdhar
    gaims1@gmail.com

Leave a Reply

  • Calendar

  • February 2010
    M T W T F S S
    « Jun    
    1234567
    891011121314
    15161718192021
    22232425262728