Subscribe to the TST RSS Feed

IIS 7: Install FastCGI & PHP on Server 2008

Dave LawlorOne of the major advantages that the Apache web server enjoyed over IIS for years has been the native support for PHP.

Most Windows Hosting you get will, if you’re lucky, install PHP for you but not support it at best.

This left some of the best open source programs out there too much of a hassle for most users. With the release of the FastCGI module you can now reliably host PHP programs on IIS.

Let’s go ahead and walk through installing the Fast CGI Module and PHP.


Install FastCGI on Server 2008

A few prerequisites for installing FastCGI would seem obvious but let’s go ahead and mention them anyway.

The first of course is an installation of Server 2008 (though this works on Vista if you are so inclined) and having IIS 7 installed already. You can also enable FastCGI while installing IIS, but for this demo I already have a virtual server with IIS 7 installed so let’s go with that.

If you need help installing the web server you can read my article on Installing IIS 7. Now let’s start:



1. Open Server Manager.

2. In the left pane expand Roles and click Web Server (IIS), then in the center pane scroll down and click Add Role Services.


IIS 7: Install FastCGI & PHP on Server 2008 - 1

3. Next on the Select Role Services screen select CGI, under Application Development, then click Next.


IIS 7: Install FastCGI & PHP on Server 2008 - 2

4. Confirm Installation Selections by reviewing the options you picked and then click Install.


IIS 7: Install FastCGI & PHP on Server 2008 - 3

5. You should see Installation Succeeded on the Installation Results screen; go ahead and click Close.


IIS 7: Install FastCGI & PHP on Server 2008 - 4

6. You will now see the CGI role service under the IIS panel.


IIS 7: Install FastCGI & PHP on Server 2008 - 5

Now that wasn’t too bad was it? You will notice that you installed CGI instead of FastCGI, but by selecting CGI it enables both. Now let’s move on to installing PHP!


Install PHP on IIS 7

When dealing with PHP there are many different versions that are in use and depending on the application you are going to be using you may need a specific version. There are also repackaged versions like those from Zend that are pre-packaged and optimized extensions that work together.

If you want to use the official release you can get it from: http://www.php.net/downloads.php

For this demo I am going to use PHP 5.2.6 Non-thread-safe installer under Windows Binaries. It is recommended to use the non-thread safe build with IIS 7 since FastCGI will ensure single threaded execution environment.

Once you download it to your server let’s get started.



1. Left click on the PHP Installer Binary.


IIS 7: Install FastCGI & PHP on Server 2008 - 6

2. You will now see the PHP Setup Wizard window, go ahead and click Next.


IIS 7: Install FastCGI & PHP on Server 2008 - 7

3. On the End-User License Agreement, go ahead and place a check in the box accepting the terms in the License Agreement and then click Next.


IIS 7: Install FastCGI & PHP on Server 2008 - 8

4. Now select a destination folder, for our example I am going to use C:\PHP5\, type or navigate to where you want to install it and click Next.


IIS 7: Install FastCGI & PHP on Server 2008 - 9

5. Now select IIS FastCGI as the web server and click Next.


IIS 7: Install FastCGI & PHP on Server 2008 - 10

6. The Choose Items to Install screen is next. I am going to stick with the default, as adding extensions that you don’t need increases your vulnerability profile.

If you have need of an additional Extension just open up the drop down and choose it, then click Next.


IIS 7: Install FastCGI & PHP on Server 2008 - 11

7. Here comes the big moment! Click Install and watch the magic happen.


IIS 7: Install FastCGI & PHP on Server 2008 - 12

8. You should see the Setup Completion screen now. Go ahead and click Finish.


IIS 7: Install FastCGI & PHP on Server 2008 - 13

9. Ok, now we will have to make a few modifications to the way PHP handles itself so we are going to modify the php.ini file.

First navigate to the place you installed PHP and open php.ini in notepad.


IIS 7: Install FastCGI & PHP on Server 2008 - 14

10. First let’s modify fastcgi.impersonate and set it to 1. Remember you are going to have to uncomment these first and then change the value, and also CTRL+F is your friend!


IIS 7: Install FastCGI & PHP on Server 2008 - 15

11. Now find cgi.fix_pathinfo and set it to 1 also, remember to uncomment by removing ;


IIS 7: Install FastCGI & PHP on Server 2008 - 16

12. Next up is cgi.force_redirect and we are going to set this to 0, and uncomment.


IIS 7: Install FastCGI & PHP on Server 2008 - 17

13. Then let’s set open_basedir to the root level of our website content directory, which I will use the default C:\inetpub


IIS 7: Install FastCGI & PHP on Server 2008 - 18

14. Now save your changes to php.ini


IIS 7: Install FastCGI & PHP on Server 2008 - 19

That’s it! Let’s go ahead and test the install, by going to a command prompt and doing the following:



1. Open a command prompt.

2. Navigate to the directory you installed PHP to.

3. Type in: PHP –info and you should see a lot of scrolling and information. This means PHP is good to go.

Below is the start of the command and output, then the second picture is the last thing that will be shown.


IIS 7: Install FastCGI & PHP on Server 2008 - 20


IIS 7: Install FastCGI & PHP on Server 2008 - 21

You have now properly installed and tested PHP on the server. Now we have to configure IIS 7 to use PHP through FastCGI.


Configure IIS7 to use PHP

IIS7 can be configured to handle PHP mappings at server or site levels, but for this example we are going to set the configuration at the server level. This just basically tells the server how to handle files with .php type extensions.



1. Open IIS Manager and select the server in the left pane and then click on Handler Mappings in the center pane.


IIS 7: Install FastCGI & PHP on Server 2008 - 22

2. In the right Action pane select Add Module Mapping…


IIS 7: Install FastCGI & PHP on Server 2008 - 23

3. Fill out the following information and click OK:

Request Path: *.php
Module: FastCgiModule
Executable: {path to your PHP install}\php-cgi.exe
Name: Whatever you want

IIS 7: Install FastCGI & PHP on Server 2008 - 24

4. You will get a popup asking if you want to create a FastCGI application, go ahead and click Yes.


IIS 7: Install FastCGI & PHP on Server 2008 - 25

5. You will now see your enabled handler in the list.


IIS 7: Install FastCGI & PHP on Server 2008 - 26

You have now successfully setup your IIS7 web server to handle PHP files via FastCgi. But don’t take my word for it, let’s go ahead and run a test.



1. Navigate to the default site directory at C:\inetpub\wwwroot

2. Create a file called info.php and place the following in the file:

<?php phpinfo(); ?>

3. Open your browser and point it at http://localhost/info.php and you should see a PHP information page similar to this:


IIS 7: Install FastCGI & PHP on Server 2008 - 27

This shows a successful handling of PHP files by IIS7. You have now configured your server to run PHP via FastCGI on IIS7.

My next article in this series will talk about installing some of the more popular databases and applications that can use PHP. If you have any requests feel free to leave a comment.



 

Related Posts:


 

85 Responses to “IIS 7: Install FastCGI & PHP on Server 2008”

  • miza Says:

    Thanks a lot i realy like it.

  • Javier Says:

    With this install, only the http:/localhost/*.php run, but if I want to run php in a site doesn’t work.

  • David Lawlor Says:

    Javier-

    What error are you seeing? If it runs in localhost, which is the default website, it should run in any other site on that server as long as you assigned the handler at the server level.

    Let me know the exact error and we can work from there.

    Dave

  • David Lawlor Says:

    Just so anyone reading this knows, I contact Javier through email and found that the error has cleared up for him so you are good to use this method to install :)

  • Sune Says:

    Great guide, but I seem to running in to a problem as well. I went through the guide two times and the php -info outputs fine, but when I call a PHP page through IIS it doesn’t work.

    For example the info.php file just gets rendered as if it was html (i can see the php code if i view the source in my browser) while another PHP script returns “500 – Internal server error.”. It is as if the mapping doesn’t work correctly, any ideas on what to try?

  • David Lawlor Says:

    Sune-

    Use the contact form to send your email details to Kasia through the site and I will get in touch and see what is going on.

    Make sure your handler for PHP is setup at the server or site level depending on where you need it.

    Also enable logging and look at the 500 error on the other script, there is a chance you are calling a module that isn’t installed.

    Dave

  • Nick Says:

    Dave,
    Great tutorial, just what I needed!

    I did all of the steps, and they appear to go pretty well.
    php.info does not render html for some reason. Any hint will be greatful.

  • David Lawlor Says:

    Nick-

    Are you getting an error for PHP.ini or is it just coming up as plain text? As above use the contact form to send in your details and I will get back to you to see what is going on.

    Dave

  • João Says:

    Hi

    I’ve followed the steps, info.php works fine but other script to users perform login no, it returns the 500 internal server error, as reported by other users. Any of those who got the error or the author of the article can explain me how they solved the problem?

    Site is still not on-line until I solve that issue.

  • David Lawlor Says:

    Joao-

    It really depends on the script. As was mentioned in the article, this is just a base install, different scripts require different extensions. Are all the necessary PHP extensions loaded for the script? You say you got a 500 error, is logging enabled so you can get an more clear error message?

    Use the contact form to send your information to Kasia and I will try and help you through this. Please send the following at least:
    Send script name
    Enable logging and get a more precise error of what the 500 is triggering on
    A list of all enabled PHP extensions.

    Thanks,
    Dave

  • Elena Says:

    Hi Dave. Thank you for your article.

    I did everything you said in the article, but when I tried to open my info.php in the browser it doesn’t show me the page you mentioned above. It just shows me the text: ‹?php phpinfo(); ?›.

    What could caused that problem?

    Thanks in advance.

  • Gary Davis Says:

    If I go to http://webguild.dyndns.org/info.php, I get the HTTP 404 error. If I go to http://localhost/info.php from the server itself, I get

    —–

    HTTP Error 404.3 – Not Found
    The page you are requesting cannot be served because of the extension configuration. If the page is a script, add a handler. If the file should be downloaded, add a MIME map.

    Most likely causes:
    * It is possible that a handler mapping is missing. By default, the static file handler processes all content.
    * The feature you are trying to use may not be installed.
    * The appropriate MIME map is not enabled for the Web site or application. (Warning: Do not create a MIME map for content that users should not download, such as .ASPX pages or .config files.)
    * If ASP.NET is not installed.

    Things you can try:
    * In system.webServer/handlers:
    o Ensure that the expected handler for the current page is mapped.
    o Pay extra attention to preconditions (for example, runtimeVersion, pipelineMode, bitness) and compare them to the settings for your application pool.
    o Pay extra attention to typographical errors in the expected handler line.

    * Please verify that the feature you are trying to use is installed.
    * Verify that the MIME map is enabled or add the MIME map for the Web site using the command-line tool appcmd.exe.
    o To set a MIME type, use the following syntax: %SystemRoot%\windows\system32\inetsrv\appcmd set config /section:staticContent /+[fileExtension='string',mimeType='string']
    o The variable fileExtension string is the file name extension and the variable mimeType string is the file type description.
    o For example, to add a MIME map for a file which has the extension “.xyz”: appcmd set config /section:staticContent /+[fileExtension='.xyz',mimeType='text/plain']

    Warning: Ensure that this MIME mapping is needed for your Web server before adding it to the list. Configuration files such as .CONFIG or dynamic scripting pages such as .ASP or .ASPX, should not be downloaded directly and should always be processed through a handler. Other files such as database files or those used to store configuration, like .XML or .MDF, are sometimes used to store configuration information. Determine if clients can download these file types before enabling them.

    * Install ASP.NET.
    * Create a tracing rule to track failed requests for this HTTP status code. For more information about creating a tracing rule for failed requests, click here.

    —-

    I did get the data out from the php -info command line OK.

    I verified the IIS 7 steps to add the handler. One thing that happened not mentioned in your detailed steps was that attempting to add E:\Program Files\PHP\php-cgi.exe resulted in a popup that said quotes are needed if there are spaces in the command (there aren’t but maybe it was complaining about the hyphen. Enclosing in quotes solved that request.

    The handler is shown as enabled for *.php.

    Any ideas on this?

    Windows Server 2008 x86

    Thanks,
    Gary Davis

  • Gary Davis Says:

    OK, I solved the problem of the 404.3.

    First, I uninstalled PHP which was installed at E:\Program Files\PHP since I thought it may be a permissions problem. I Installed it at E:\PHP. This did not help, even when adding NETWORK SERVICE to the securities list.

    When the Handler Mapping was added this time, it did not complain about the quotes.

    I then re-added the Handler Mappings at the web site level (Default Web Site) since it did not show up there even though it was mapped at the server level.

    Now, the Info.php ran!

    Thanks,
    Gary Davis

  • David Lawlor Says:

    Gary-

    Thanks for the follow-up on your issue. The reason the handler wanted quotes is because of the space in “Program Files” since that is part of the path for your command line and while the Windows GUI handles the space ok, the command line would need the quotes.

    I am surprised that adding the mapping at the server level did not get inherited by the default website. I will run a test on my server to see if I can replicate that issue.

    Thanks again for your follow-up.

    Dave

  • LIX Says:

    Elena and everybody who gets plain php code instead of correct result – symbols ” in this guide are replaced with some Unicode symbols which look a lot like them. Therefore php code won’t work, if you are trying to run code copy-pasted from this article. Some little nasty mistake.

  • LIX Says:

    It seems that engine of forum eats this symbols.
    I meant greater-than sign > and less-than sign <

  • Colin Says:

    I followed it step by step and it’s didn’t work for me in windows server 2008
    if I go to the http://localhost/info.php I get an HTTP 404 Not Found error…

  • David Lawlor Says:

    Colin-

    A 404 error should only be evident if your info.php file was not in the right location. Check the root path for your default website which should be by default:
    %SystemDrive%\inetpub\wwwroot and make sure that the info.php file is found under that directory. If PHP was an issue you would have either seen only the text in the info.php file or gotten a 500 error.

    If this is a server I could access send your information through the contact form on this site and I will contact you to see if I can give you a hand.

    Dave

  • Wesley Says:

    I too had the same issue, where the first php file I created (per the tutorial) did not render in my website directory. After hours of troubleshooting, I simply created another PHP file and that one runs fine, with the sample script copied and pasted. And still the original PHP file I created does not render. I verified the extention, made sure it was not a text file… it just won’t run. If I run it on the localhost, I get a 500 error by the way with that file, but not the new one I created. They are both in the same folder, appear to have the same permissions. Wierd.. but anyway.. this sounds like the same problem everyone else is having.

  • Wesley Says:

    So maybe LIX is right.. although, I copied it straight into a text file from this site.. and I copied it from that text file to my new php file (which did work).. so I still don’t get it completely.. but it kinda makes sense.

  • Cal Says:

    I don’t know too much about php, MySQL, or server 2008, but I followed instructions from this site exactly. IIS7 and info.php worked fine. MySQL Command Line Client works fine. location of folders (C:\PHP5; C:\Program Files\MySQL) I am comfortable with SQL so I don’t need a GUI for it. I am trying to get php to connect to mySQL using the below code. I assume user and password are a user on the server. Is there some setting I’m missing or some file that needs to be moved? Below is the code:

    IExplorer displays:
    PHP Fatal error: Call to undefined function mysql_connect() in C:\inetpub\wwwroot\mySQL.php on line 5

    Thanks ahead, any hint would be appreciated!

  • Cal Says:

    lol, sorry code disappered I took out the this time:

    $user=”staff”;
    $password=”notrealpassword”;
    $database=”mysqldb”;
    mysql_connect(localhost,$user,$password);
    @mysql_select_db($database) or die( “Unable to select database”);
    $query=”CREATE TABLE contacts (id int(6) NOT NULL auto_increment,first varchar(15) NOT NULL,last varchar(15) NOT NULL,phone varchar(20) NOT NULL,mobile varchar(20) NOT NULL,fax varchar(20) NOT NULL,email varchar(30) NOT NULL,web varchar(30) NOT NULL,PRIMARY KEY (id),UNIQUE id (id),KEY id_2 (id))”;
    mysql_query($query);
    mysql_close();

  • David Lawlor Says:

    Cal-

    Is the MySQL extension configured for PHP? Make sure the following line is uncommented out in your php.ini

    extension=php_mysql.dll

    Let me know if that works,
    Dave

  • Cal Says:

    It didn’t make a difference. I tried “extension=php_mysql.dll” and “extension=mysql.dll” seperately followed with the php -info in the “PHP5″ directory. I’m wondering if maybe the user should be blank(”"), Administrator, or root? Thanks for the fast response! I’m wondering if I should redo the whole server following different instructions.

  • Cal Says:

    I found the “php.ini” file in the PHP5 folder and did not find extension=php_mysql.dll so I typed it in. Is there another “php.ini” file? If so where is it?

  • David Lawlor Says:

    No there should only be one php.ini, it was the same one you modified in the article above.

    I dont think it is a permission issue because the error is a PHP one and it is because the Mysql handler isnt functioning properly. You may need to restart the server to get the extension to take.

    If you want to make sure rerun the installation above for PHP and in step 6 go into the dropdown for extensions and choose MySQL from the extensions.

    I emailed you directly, feel free to contact me directly and I will post a summary on here when we figure it out.

    Dave

  • Matthew Says:

    Great guide…

    one question though, using the .exe php installers, how can i add mysqli support, it seems it is listed under the php.ini file, but i have pages that wont work, i had them working under ISAPI module and by un-comment and copying dlls around.. but the installer has no dll to move around, should mysql / mysqli just work..

  • Matthew Says:

    ignore that last one, silly me didnt choose the mysql items during the installer :)

  • tween Says:

    Hi-
    16 hours and no luck. 500 internal server error, 403 errors. Uninstalled, reinstalled php, mysql. PHP Info won’t run. Ran for most of the day until I reinstalled php 5.2.
    .html files work, php files don’t. trying to install wordpress on server 2008. server has sharepoint on it. can’t take it off as I host sharepoint.

    500 – Internal server error.
    There is a problem with the resource you are looking for, and it cannot be displayed.

    IIS handlers configured properly. default page set to index.php.

    Any suggestions would be greatly appreciated.
    P.

  • Calvin Says:

    Thanks for a Great guide.
    Unfortunaltely PHP info runs on the default site, The Handler Mapping are there and carry over to the other sites but it will not run outside of the default on another site, I keep getting 500 – Internal server error.
    There is a problem with the resource you are looking for, and it cannot be displayed.

    I know other people have had this issue 500 issue, any hints or help would be greatly appreciated.

  • David Lawlor Says:

    Calvin -

    Check the logs for the exact 500 error it should be more specific. Though what catches most people is that the new site directory is outside the directory specified in step 13 which is the open_basedir statement. All sites that you want to work with PHP have to fall under this top level directory. If you are using a directory outside what you placed in that path they will not work.

    Let me know if that helps, or if you can find a more specific error.

    Dave

  • Matthew Says:

    When I try to access http://192.168.0.88/info.php it works. When I try to access http://localhost/info.php it does not work. When it does not work I get a error 404.

    When I access http://192.168.0.88/info.php remotely it works. However, when i just do http://192.168.0.88/ no site loades up I get an error 500.

    Any ideas??

  • Matthew Says:

    my logfile:

    #Date: 2008-12-29 17:57:14
    #Fields: date time s-ip cs-method cs-uri-stem cs-uri-query s-port cs-username c-ip cs(User-Agent) sc-status sc-substatus sc-win32-status time-taken
    2008-12-29 17:57:14 192.168.0.88 GET / – 80 – 192.168.0.25 Mozilla/5.0+(Windows;+U;+Windows+NT+6.0;+en-US;+rv:1.9.0.5)+Gecko/2008120122+Firefox/3.0.5 500 0 0 234
    2008-12-29 17:59:29 192.168.0.88 GET / – 80 – 192.168.0.25 Mozilla/5.0+(Windows;+U;+Windows+NT+6.0;+en-US;+rv:1.9.0.5)+Gecko/2008120122+Firefox/3.0.5 500 0 0 187
    2008-12-29 18:00:48 192.168.0.88 GET / – 80 – 192.168.0.16 Mozilla/4.0+(compatible;+MSIE+7.0;+Windows+NT+5.1;+.NET+CLR+1.1.4322;+.NET+CLR+2.0.50727;+.NET+CLR+3.0.04506.30;+.NET+CLR+3.0.04506.648) 500 0 0 171

  • David Lawlor Says:

    Matthew -

    Ok let me ask a few more specifics to make sure I know exactly where you are at.

    Ok so it works if you go directly to the info.php with a IP so we know it is working.

    Since it doesnt work with localhost can you tell me how this server is setup? First did you create a new site for the PHP or are you using the default one? Does the server have more than one IP assigned to it?

    For the remote answer it is more than likely your default document setting for the site. Make sure you have a default document there for the site. Or set your default document to info.php if you dont have any other documents setup right now.

    Let me know how much that clears up and we can go from there.

    Dave

  • Matthew Says:

    The server is a 2008 virtual server sitting on a 2008 server. It hosts AD/DNS/IIS. It is the primary AD/DNS but there is a secondary on the network as well and it’s all a member of a domain. As far as the virtual server goes, no it only knows there is one IP.

    I have my default document set to index.php. I even renamed index.php to info.php and info.php to index.php and accessed http://192.168.0.88 and the phpinfo page showed up just fine.

    I believe now that because of what i just mentioned there is something in my index.php that is holding me up. This site has been working for a few years and was working just fine on a IIS 6 (actually still is i’m just deploying a backup on iis 7). There is a mysql connection and the mysql is installed with the data populated and i can connect to it and see all the data just fine w/ sqlyog (sql browser).

    I looked up error 500 0 0 171 (i believe) and it pointed to something about SMTP connection. My site does pass the password to our internal email but that resides on a remote linux box. Also, my connect script for mysql calls for locahost (remember i can’t connect to localhost) so i changed that to the IP instead but no luck.

  • Matthew Says:

    oh also, yes, i created a new site and am not using the default one nor am i using the default pool.

    I tried to use them though and get the same results. they are both pointing to the same directory to use. (i stopped the default site/pool while trying to run the new site/pool)

  • Matthew Says:

    I’ve stumped him!! :)

  • Matthew Says:

    #Fields: date time s-ip cs-method cs-uri-stem cs-uri-query s-port cs-username c-ip cs(User-Agent) sc-status sc-substatus sc-win32-status time-taken
    2009-01-02 03:06:17 192.168.0.88 GET / – 80 – 68.229.237.116 Mozilla/5.0+(Windows;+U;+Windows+NT+6.0;+en-US;+rv:1.9.0.5)+Gecko/2008120122+Firefox/3.0.5 500 0 0 218
    2009-01-02 03:06:19 192.168.0.88 GET / – 80 – 68.229.237.116 Mozilla/5.0+(Windows;+U;+Windows+NT+6.0;+en-US;+rv:1.9.0.5)+Gecko/2008120122+Firefox/3.0.5 500 0 0 234
    2009-01-02 03:06:19 192.168.0.88 GET / – 80 – 68.229.237.116 Mozilla/5.0+(Windows;+U;+Windows+NT+6.0;+en-US;+rv:1.9.0.5)+Gecko/2008120122+Firefox/3.0.5 500 0 0 218
    2009-01-02 03:06:19 192.168.0.88 GET / – 80 – 68.229.237.116 Mozilla/5.0+(Windows;+U;+Windows+NT+6.0;+en-US;+rv:1.9.0.5)+Gecko/2008120122+Firefox/3.0.5 500 0 0 218
    2009-01-02 03:06:19 192.168.0.88 GET / – 80 – 68.229.237.116 Mozilla/5.0+(Windows;+U;+Windows+NT+6.0;+en-US;+rv:1.9.0.5)+Gecko/2008120122+Firefox/3.0.5 500 0 0 250
    2009-01-02 03:06:20 192.168.0.88 GET / – 80 – 68.229.237.116 Mozilla/5.0+(Windows;+U;+Windows+NT+6.0;+en-US;+rv:1.9.0.5)+Gecko/2008120122+Firefox/3.0.5 500 0 0 234
    2009-01-02 03:06:20 192.168.0.88 GET / – 80 – 68.229.237.116 Mozilla/5.0+(Windows;+U;+Windows+NT+6.0;+en-US;+rv:1.9.0.5)+Gecko/2008120122+Firefox/3.0.5 500 0 0 218
    2009-01-02 03:06:20 192.168.0.88 GET / – 80 – 68.229.237.116 Mozilla/5.0+(Windows;+U;+Windows+NT+6.0;+en-US;+rv:1.9.0.5)+Gecko/2008120122+Firefox/3.0.5 500 0 0 218
    2009-01-02 03:06:20 192.168.0.88 GET / – 80 – 68.229.237.116 Mozilla/5.0+(Windows;+U;+Windows+NT+6.0;+en-US;+rv:1.9.0.5)+Gecko/2008120122+Firefox/3.0.5 500 0 0 234
    2009-01-02 03:06:20 192.168.0.88 GET / – 80 – 68.229.237.116 Mozilla/5.0+(Windows;+U;+Windows+NT+6.0;+en-US;+rv:1.9.0.5)+Gecko/2008120122+Firefox/3.0.5 500 0 0 250
    2009-01-02 03:06:22 192.168.0.88 GET / – 80 – 68.229.237.116 Mozilla/5.0+(Windows;+U;+Windows+NT+6.0;+en-US;+rv:1.9.0.5)+Gecko/2008120122+Firefox/3.0.5 500 0 0 218
    2009-01-02 03:06:22 192.168.0.88 GET / – 80 – 68.229.237.116 Mozilla/5.0+(Windows;+U;+Windows+NT+6.0;+en-US;+rv:1.9.0.5)+Gecko/2008120122+Firefox/3.0.5 500 0 0 234

  • Matthew Says:

    ok…uninstalled IIS7. Reinstalled IIS7 and PHP 5.2 as per the following step by step guide:

    http://learn.iis.net/page.aspx/246/using-fastcgi-to-host-php-applications-on-iis-70/

    (this looks identical to yours and i followed yours originally)

    I still get the following errors:

    2009-01-02 04:36:16 192.168.0.88 GET / – 80 – 68.229.237.116 Mozilla/5.0+(Windows;+U;+Windows+NT+6.0;+en-US;+rv:1.9.0.5)+Gecko/2008120122+Firefox/3.0.5 500 0 0 234
    2009-01-02 04:36:16 192.168.0.88 GET / – 80 – 68.229.237.116 Mozilla/5.0+(Windows;+U;+Windows+NT+6.0;+en-US;+rv:1.9.0.5)+Gecko/2008120122+Firefox/3.0.5 500 0 0 187
    2009-01-02 04:36:16 192.168.0.88 GET / – 80 – 68.229.237.116 Mozilla/5.0+(Windows;+U;+Windows+NT+6.0;+en-US;+rv:1.9.0.5)+Gecko/2008120122+Firefox/3.0.5 500 0 0 203
    2009-01-02 04:36:16 192.168.0.88 GET / – 80 – 68.229.237.116 Mozilla/5.0+(Windows;+U;+Windows+NT+6.0;+en-US;+rv:1.9.0.5)+Gecko/2008120122+Firefox/3.0.5 500 0 0 203
    2009-01-02 04:36:16 192.168.0.88 GET / – 80 – 68.229.237.116 Mozilla/5.0+(Windows;+U;+Windows+NT+6.0;+en-US;+rv:1.9.0.5)+Gecko/2008120122+Firefox/3.0.5 500 0 0 187

    if any advice please email hardwerk@gmail.com I really appreciate any info.

  • Matthew Says:

    My site runs just fine on IIS 6. Is that because of ISAPI? Is there any reason my site would require ISAPI vs FastCGI?

  • dirt Says:

    500 Error SOLUTION:

    Add “IIS_WPG” group with +RXL permissions to C:\PHP5 directory

  • Mike Taylor Says:

    Hello.

    Thank you for well made document. I was nicely done.

    I have Server 2008 and downloaded PHP 5.2.8. I followed your steps precisely, but I received a 404 error. Anyhow, I found the problem. My server settings, by default, was set to “hide extensions for known file types.” I unselected that option, removed the trailing .txt from the info.php file that was created, and there it worked.

    I typically show file extensions, however; this being a fresh install of Server 2008, I didn’t get around doing that just yet. So naturally that error threw me into a loop.

    After reading some of the responses, I just thought I mention that as I think some people may have ran into a similiar sistuation.

    Mike

  • [...] IIS7: Install FastCGI & PHP on Server 2008 by Dave Lawlor [...]

  • Anthony Says:

    Thanks for the help work 1st time was going crazy.

  • Shuoming Says:

    Thanks so much for all the information you put up there!

    I installed php 5.3 nts x64 and Mysql 5 x64 on Windows 2008×64 (hardware and operatesysem)with ii7 configed fastcgi. They run individually fine. php -info tested good. But when installing moodle 1.9.4 I got error like this: HTTP error 500.0 – internal Server Error The page cannot be displayed because an internal server error has occurred. Detail Error Information:

    Module FasModule: FastCgiModule
    Notification: ExecuteRequestHandler
    Handler: PHP via FastCGI
    Error Code: 0×00000000
    Requested URL: http://localhost:80/moodle/index.php
    Physical Path :C:\inetpub\wwwroot\moodle\index.php
    Logon Method :Anonymous
    Logon User: Anonymous

    Could you please take a look?

  • Amster Says:

    Excellent tutorial mate. Worked for me on Vista+II7

    Thank for taking the time out to share this information – you’re a good guy.

    Now all I need to do is set up MySql on Vista! (need another walk through like this lol!)

    Cheers

  • Steve Says:

    So I installed PHP 5.2.6 on Server 2008 Web/IIS 7. I configured FastCGI as above.

    My phpinfo.php works fine. I setup a PHP application (amiroCMS) all written in PHP and I was able to configure it, set it completely up, config a mysql DB etc. But when I get to the login page after the config and actually login I get an error:

    HTTP Error 500.0 – Internal Server Error
    There is a problem with the resource you are looking for, so it cannot be displayed

    Module FastCgiModule
    Notification ExecuteRequestHandler
    Handler PHP_via_FastCGI
    Error Code 0×8007000d
    Requested URL http://auctionmasters.com:80/amiro/_admin/index.php
    Physical Path \www\AuctionMasters\amiro\_admin\index.php
    Logon Method Anonymous
    Logon User Anonymous

    Nothing I do will make this error go away. I can render other php pages and phpinfo works fine, but for some reason it fails upon the actual login.

    I also installed phpMyadmin for Mysql administration, and that ever works fine – I can create, modify delete db’s etc.
    Ironically, MS has no info on the 0×8007000d error and no info on FastCGI errors.
    Enabling PHP logging does nothing either.

    Any input on the error or how to trace down what the cause it?

  • imperia Says:

    I’ve managed to fix 500.0 Internal server errors I was getting with default PHP Version 5.2.9-2 installation. Here is what I did. First I followed the guide above. Then I ran Command Prompt (with administrator rights). Then I ran php-cgi. I got errors like this:

    PHP Warning: PHP Startup: Unable to load dynamic library ‘C:\Program Files\PHP\ext\php_mssql.dll’ – The specified module could not be found.
    in Unknown on line 0
    PHP Warning: PHP Startup: Unable to load dynamic library ‘C:\Program Files\PHP\ext\php_pdo_mssql.dll’ – The specified module could not be found.
    in Unknown on line 0
    PHP Warning: PHP Startup: Unable to load dynamic library ‘C:\Program Files\PHP\ext\php_pdo_oci.dll’ – The specified module could not be found.
    in Unknown on line 0
    PHP Warning: PHP Startup: Unable to load dynamic library ‘C:\Program Files\PHP\ext\php_pdo_oci8.dll’ – The specified module could not be found.
    in Unknown on line 0
    PHP Warning: PHP Startup: Unable to load dynamic library ‘C:\Program Files\PHP\ext\php_pdo_pgsql.dll’ – The specified module could not be found.
    in Unknown on line 0
    PHP Warning: PHP Startup: Unable to load dynamic library ‘C:\Program Files\PHP\ext\php_pdo_sqlite_external.dll’ – The specified module could not be found.
    in Unknown on line 0
    PHP Warning: PHP Startup: Unable to load dynamic library ‘C:\Program Files\PHP\ext\php_pgsql.dll’ – The specified module could not be found.
    in Unknown on line 0
    PHP Warning: PHP Startup: Unable to load dynamic library ‘C:\Program Files\PHP\ext\php_pspell.dll’ – The specified module could not be found.
    in Unknown on line 0
    PHP Warning: PHP Startup: Unable to load dynamic library ‘C:\Program Files\PHP\ext\php_sybase_ct.dll’ – The specified module could not be found.
    in Unknown on line 0

    Run Notepad (with administrator rights) and open php.ini from C:\Program Files\PHP
    Go to the end of the file. Stop php from loading the modules that you had error with. Remove each 2 lines with problem modules. Example

    [PHP_MSSQL]
    extension=php_mssql.dll

    ^^^^ remove both or comment with ;
    Do this for each module that you got error with.

    Save the ini file and run again php-cgi to see if you have fixed the errors.

    Try running again your phpinfo.php script in your browser to see if its working.

    I guess the right way to install php is to enable modules that you really need, not all of them. Maybe the errors are caused by bad “Module Settings” in php.ini file, because the actual .dll files are present in the \ext folder. So the error “The specified module could not be found.” is misleading.

    I hope this helps. If you are still unable to make it work, I may post my php.ini settings here.
    Good luck.

  • Daniel Grogan Says:

    Absolutely excellent, very easy to follow

  • mmkeebler Says:

    This method worked great for me. Thanks for the great tutorial.

  • Joseph Hillhouse Says:

    THANK YOU!!!!!! so much. I have tried everything and spend at least 12 hours on it installing from the zip package and the installer using fastcgi, cgi, and isapi script but it would always go wrong. Finally it works and I can connect to my database. I was almost ready to give up.

  • Max Says:

    Thank you for the super clear explanation! Worked on the first try, thanks!

  • [...] like to thank Dave Lawlor and his post for helping me to set up php and mysql. Of course its never as easy as it seems. I’ve had to [...]

  • Mbalthrop Says:

    Thank you, this was exactly what i was looking for.

  • Lindsay Says:

    Dave,
    I read through this, and a whole bunch of other google results for the 500 internal server error.

    I am still getting it.
    specifically, whenever php tries to do anything with mysql
    i can run phpinfo() in a script from a browser just fine.
    if the only function in my php script is mysql_connect(), with proper credentials for mysql, i get the 500 error.

    My problem here is that i am trying to help the windows server administrator figure this out. I am a *nix admin, not windows.

    They are running windows server 2008. i think their environment _might_ be virtualized, but i am not sure.

    Any ideas?

  • Henrik Hansen Says:

    Hi Dave, at first i must say… rly rly nice work you do for help us out “out here in the world” :)

    I have follow all your guides to get a windows server 2008 std, to work as IIS 7 whit PHP and mySQL whit phpmyadmin.

    As faar all looking good – i mean, my phpinfo.php works fine – mySQL db works i can manage it by GUI tools, and phpmyadmin.

    and it`s abit strange how to try explain the problems i do have – but i try:

    exampel site:
    1.) i do have the real site ( old server ) here: http://www.tinglev-bogtrykkeri.dk
    - all works fine and includes and connections to mySQL works.

    2.) i do have the same site ( on new server ) here: http://tinglev-bogtrykkeri.dk
    - its look like the includes work, but don`t get the “my SQL data” on the site.
    - when i try view source code, i can see the indcludes on the site, whit not are normaly.

    On thats it`s seem like “php not work” – but when i try make a php info file on same “web site” http://tinglev-bogtrykkeri.dk/phpinfo.php – it`s show like it should work?

    Do you or some have anny idea what`s wrong, and how to fix it?
    - rly almost about to get crazy about it! :)

    Thanks alot, Henrik

  • Johnny Burnette Says:

    Nice job! You make it look so easy.

  • Li Hoang Says:

    Thanks so much for this info. I’ve been stressing my PHP set-up because I kept receiving this error: “Unable to load dynamic library ‘C:\Program Files (x86)\PHP\ext\php_mssql.dll’”

    But with your configurations, it’s finally gone. My PHP instructor couldn’t even help me.

    Thanks so much!

  • Bharathi Says:

    nice article dude.will helps me a lot.

  • Justin Says:

    First off, very nice guide.

    However, I also have a failed attempt.

    I did this on a W2K8 x64 machine. I installed PHP 5.3 into C:\PHP5.

    One additional comment I’d like to add is that I found no need to “Add Module Mapping”. It was added for me. With an addional attribute. File Type is listed as File or Folder instead of unspecified.

    When I try to run your sample code I get 500 as well. The log file tells me nothing other then 500 0 0.

    Installing PHP on IIS6 requires additional security permissions be set. Yet here in your tut I see no permissions?

    Are there any missing permissions?

    I then removed PHP 5.3 and reinstalled 5.2.10 and this time installed it into the PROGRAM FILES(x86) folder and have the same exact issue. Error 500 when running PHP PHPINFO

  • Justin Says:

    I feel like a heel. I screwed up the basedir option on my second go around. When I fixed it, it started to work.

    So, one of two things fixed my problem on a x64 machine. Either:

    1. Not using 5.3 and going back to 5.2.10 worked.
    or
    2. Installing PHP into the x86 program files folder worked.

    Or both.

    Now I have a new problem. I can only run PHP from a single folder. If I select C:\ as the basedir, no folder works.

    Why do I have to select one specific folder? I run lots of website from this server that require PHP.

    C:\web
    C:\test
    C:\xxxxx

    And so forth. I need to put them ALL into a single folder and run them from that?

    C:\PHP Sites\web
    C:\PHP Sites\test
    C:\PHP Sites\xxxxxx

    ???

  • Duy Says:

    please help me. i followed every single step that was posted in here and i haven’t been able to make my site running. i installed iis7, php but everytime i go to http://localhost, it works fine. but if i go to http://localhost/phpinfo.php, it says http404 not found. can you help me please. please email me if you want phone number to contact me. thank you.

  • Hi Duy,

    It’s difficult to say what could be causing this, but here’s what you can do. Start by taking a closer look at what your error message is saying.

    Is it a 404.0 message? or is there another number after the dot that’s not a 0? You should also be seeing some suggested “most likely causes” and “what you can try.”

    Here is an article that will help you find out more information about IIS errors and how to troubleshoot them: http://mvolo.com/blogs/serverside/archive/2007/07/26/Troubleshoot-IIS7-errors-like-a-pro.aspx

    If you’re still having problems, send us more info and we’ll try to help you out.

  • Duy Says:

    no i solved the problem. i am the stupidest person ever. lol
    my info.php got a .txt at the end. lol unbeliveable took me all day for this thing. lol thank you for your help.

  • Dan Sexton Says:

    I too was getting the 500 error with PHP 5.3. I went to the command line and redirected the php-cgi to a file like this:

    php-cgi E:\websites\info.php >test.htm

    The resulting test.htm opened up and displayed all of the information just fine, so it wasn’t the creation of the file that wasn’t working. However when I executed the command I did get this text on my screen:

    “PHP Warning: phpinfo(): It is not safe to rely on the system’s timezone setting
    s. You are *required* to use the date.timezone setting or the date_default_timez
    one_set() function. In case you used any of those methods and you are still gett
    ing this warning, you most likely misspelled the timezone identifier. We selecte
    d ‘America/Chicago’ for ‘-5.0/DST’ instead”

    I went into my php.ini file and set date.timezone = America/Central and now everything is working.

    Perhaps this is a new requirement for 5.3? Odd that they did not create a default…

    Hope this helps, thanks for a great easy to follow guide.

  • Be aware that if you create a file in windows server 2008 the extensions is hidden so:

    info.php would be info.php.txt and that can create your error.

    Rename it in dos by: rename info.php.txt info.php

  • Adam Lavery Says:

    Mr Sexton, you’re a star!

    Been scratching around for hours trying to figure out why something so simple should cause such a headache. Quite why PHP can’t rely on the system’s timezone or if this is a pre-requisite to running PHP, they couldn’t have included the question during the installation is beyond me!

    It’s a shame this is at the bottom of this post – I’m sure many will have given up by the time they get here. Perhaps the author could update his post to include this essential information for the latest PHP release?

    To whoever is responsible for PHP – don’t be so stupid and fix this!!

  • Brady Wilson Says:

    Most of these posts are old but I though I would add my two cents…

    I was getting the 404.3 message as well – couldn’t figure it out because it really looked like it was setup correctly.

    It appears that IIS does not like spaces in the Handler name – so an entry for “PHP via FastCGI” will give the error whereas “PHP_via_FastCGI” will work.

    Fixed my issue anyway.

    -b

  • Having issues installing PHP on Windows Server 2008 64-bit system. Downloaded the VC9 x64 Non Thread Safe zip package from: http://windows.php.net/qa/ and can’t remember where I found the .msi version (php-5.3-win32-VC9-x64-latest.msi) but I ended up getting the error message: ‘The installer has encountered an unexpected error installing the package. This may indicate a problem with this package. The error code is 2356.’

    I unpackaged the zip to the C:\PHP5 directory a week or so ago and got a successful handling return by inputing http://localhost/info.php into a browser, but then there were other issues I can’t quite remember. Am starting the process over and would like to get some guidance if the zip package is the way to go, if there is a different installer I should download or if I need to go the SVN route, or… Please advise. Thanks

  • VooDoo Says:

    yes, DAN Sexton is a BIG STAR!!
    Thanks Dan for posting you tip here!!
    Cya
    VooDoo

  • Dez Says:

    I am having serious problems with my php or something. I have uninstalled IIS…PHP, MYSQL several times and i am still getting the same results. Basically my info file is showing great with no problems. I am trying toinstall a software script and when i go to the install.php on server i get:
    PHP Notice: Use of undefined constant d79260 – assumed ‘d79260′ in C:\inetpub\wwwroot\videogirls\_setup\install.php(5) : eval()’d code(2) : eval()’d code on line 1 PHP Notice: Undefined variable: ntmfcloaded in C:\inetpub\wwwroot\videogirls\_setup\install.php(5) : eval()’d code(2) : eval()’d code on line 1 PHP Notice: Use of undefined constant d79260 – assumed ‘d79260′ in C:\inetpub\wwwroot\videogirls\_setup\install.php(5) : eval()’d code(2) : eval()’d code on line 1 PHP Notice: Use of undefined constant d87260 – assumed ‘d87260′ in C:\inetpub\wwwroot\videogirls\_setup\install.php(5) : eval()’d code(2) : eval()’d code on line 1 PHP Notice: Undefined index: d87260 in C:\inetpub\wwwroot\videogirls\_setup\install.php(5) : eval()’d code(2) : eval()’d code on line 1 PHP Notice: Use of undefined constant d87260 – assumed ‘d87260′ in C:\inetpub\wwwroot\videogirls\_setup\install.php(5) : eval()’d code(2) : eval()’d code on line 1 PHP Notice: Use of undefined constant d98260 – assumed ‘d98260′ in

    That is just some of the code….http://localhost shows find and phpmyadmin shows with no issues….its just this install.php that is giving problems

  • Murat Bilga Says:

    Hi Dave. Thank you for your article.

  • Joo Says:

    Hi I followed your instructure and I am able to display
    info.php, but I am getting this error message when I submit a form to send_form_email.php. Please help!

    Thanks,

    HTTP Error 500.0 – Internal Server Error
    The page cannot be displayed because an internal server error has occurred.

    Module FastCgiModule
    Notification ExecuteRequestHandler
    Handler FastCGI PHP
    Error Code 0×00000000
    Requested URL http://172.16.82.100:80/send_form_email.php
    Physical Path C:\inetpub\CDCISite\send_form_email.php
    Logon Method Anonymous
    Logon User Anonymous

    IIS received the request; however, an internal error occurred during the processing of the request. The root cause of this error depends on which module handles the request and what was happening in the worker process when this error occurred.
    IIS was not able to access the web.config file for the Web site or application. This can occur if the NTFS permissions are set incorrectly.
    IIS was not able to process configuration for the Web site or application.
    The authenticated user does not have permission to use this DLL.
    The request is mapped to a managed handler but the .NET Extensibility Feature is not installed.

  • HcUser Says:

    To any who get the 500 error-

    This 500 could be caused by a PHP error message generated by the application. Your best bets are to turn off fast cgi logging, and to set up a php error log. The following entries in your php.ini flie should do the trick:

    fastcgi.logging = 0
    log_errors=on
    error_reporting = E_ALL
    error_log=”C:\Windows\Temp\php-errors.log”

    The important things here are to make sure that these are the only declarations of those settings that aren’t commented out in the php.ini flie. Also, that “C:\Windows\Temp” is where your system TEMP directory is.

    You should restart IIS, and then re-run your application. If it is a PHP error that is causing the 500, you should now be able to see the PHP error in the php-errors.log file. If it was a PHP warning or notice, or other non-error message, it should now be displayed on the screen, as well as logged in php-errors.log

    Now we can party like a rock star-

  • Lynn Breaux Says:

    I had the problem with localhost/info.php and found that my default website was not going to wwwroot. I put it in http://www.lynnbreaux.com and it works fine.

  • fm3000 Says:

    Hey man! thx, great tutorial, I got my 500 fixed after reading the timezone hint above!

    cheers for that.

  • John O Says:

    I am building a new webserver using server 2008 64bit, installed the latest version of PHP (5.3.0), everything goes well until I try the localhost/info.php, I get a HTTP 500 internal Server Error, Have read through some of the above comments, but have not figured it out yet.

  • John O Says:

    It started working this morning, all is good!

  • Yurii Says:

    Hello!

    meybe you can explain, how to render php when used

    I have success when render , but fail when use syntax above.

    regards

  • Yurii Says:

    fail when [?= SOMEthing ?]

    but o.k. when [?php ?]

  • Todd Says:

    I am new to most of this. I have read through all these post and all seems to be working but this.

    In what format do I put:
    in the info.php file? Not sure if I use notepad or what.
    Thank you for any help

  • Simon Price Says:

    I have set this up and get a 404 page not found error and cant figure out why…. any ideas?

  • Eric Tanefo Says:

    To Dave Lawlor,

    Can you develop a package that will automate this installation process.
    I am interested in running some PHP web sites using MySQL on a server running SBS 2008.
    Thsi wil be extremely helpful since I do not want to spend my time doing this and troubleshooting the problems.

    Do you offer technical services for installation of the Apache HTTP Server as well as MySQL and PHP. I am thinking about a scenario where both IIS ad Apache could co-exist.

    Thanks,

  • Grahame Says:

    Dave,

    Great post – thank you. I’m hoping you – or another reader – can help with a 404 error, however.

    Have installed PSP 5.3.1 (msi) on SBS 2008R2. Modified php.ini & running “PHP -info” from command line at C:\PHP works fine.

    When I open http://localhost.inffo.php I get 404 Not Found error. Have checked IIS handler mapping etc. & all seems ok.

    Interestingly, if I open http://localhost I get our Sharepoint ‘Team Site’, instead of the IIS page. I’m not sure if this is normal & possibly related to the 404 error?

    Regards,
    Grahame

  • Raymond Besiga Says:

    You’re a life saver.Thank you so much!! I have been trying to make this work for quite some time.

Leave A Comment: