Installing PHP 5 on IIS in 5 simple steps

Categories:

Yes, yet another PHP 5 installation guide. Why write one when there are already dozens of them out there? Well there are two main reasons: firstly I will be writing a lot of guides that require PHP to be installed and working and I will need something to point people to who have yet to install PHP. Secondly, I have read a lot of the guides out there and found that a good portion of them over complicate the process. It really should not be that hard or perplexing. In this guide we'll break down the process of installing PHP 5 on IIS into 5 simple steps that are easy to follow that works for IIS 5, IIS 5.1 and IIS 6.

NOTE: This guide is intended for use with PHP 5.2.x and below. A guide for PHP 5.3 and above will be published in the coming weeks.

So what are these 5 simple steps? In a nutshell, this is all you need to do to install PHP 5 on IIS;

  1. Download and Extract PHP 5 (we'll install PHP 5.2.1 on IIS 5.1 in this guide)
  2. Set your environment variables
  3. Set the PHP application mapping in IIS
  4. Configure php.ini
  5. Restart & Verify

Just before we continue I thought it pertinent to mention that it if you have already installed, or attempted to install PHP on your system then you must remove all traces of that install before continuing. If ANY PHP files exist anywhere else on your system that are accessible via the PATH environment variable, then it is very possible (even probable if the previous version of PHP was different) that you will have issues with hosting PHP content.

If you are wanting to install PHP 4, then the process is slightly more complex than installing PHP 5 and involves steps not covered in this guide. Not to worry as it is even easier for you. All you have to do is download the IIS Aid PHP Installer from this site and run the fully automated GUI installer. This installer will completely setup your PHP 4 environment, including all environment variables, IIS scriptmaps and IIS 6 web extension. The particular advantage of this installer is that it configures PHP 4 to use FastCGI mode as well as an Opcode cache for maximum performance. Expect to see some articles of just how much faster here in the future.

1. Download and Extract PHP 5

Nothing taxing about this, simply go to the PHP download page and download the latest PHP zip package from under the "Windows Binaries" section, along with the latest PECL Win32 binaries (do not get the ones marked "non-thread-safe" unless you plan to use CGI/FastCGI as otherwise you run the risk of a race condition). Save the PHP zip package to the directory where you will want to install PHP (e.g. D:\PHP), and then extract. Once extracted you'll see inside your PHP installation directory a sub directory called "ext". Save the PECL Win32 binaries download into it (e.g D:\PHP\ext), and then extract. Your PHP install directory should now contain all the content of your PHP zip package file, and your ext sub directory should contain the contents of your PECL Win32 binaries file. From here move back to the root of you PHP installation directory (e.g. D:\PHP) and create three directories, one called sessions, one called upload and one called log. In the log directory create a new file called php.log. First step licked.

Comments

Brashquido's picture

You have definitely

You have definitely uncommented php_mysql.dll in your php.ini file? If so, then have a look at the path for the "Loaded Configuration File" value near the top of your phpinfo page. Is this correct?

----------------
Dominic Ryan
5 x Microsoft IIS MVP, MCSE, MCSA
IIS Aid owner/webmaster

Anonymous's picture

Excellent Guide

Thanks a lot for such a excellent and elaborative guide. Really helpful.

Regards

Anonymous's picture

Problem installing on IIS 7

Hi, and first thank you for this nice guide.

However I have problems installing on IIS 7 as the interface is really different from previous versions and I am far from beeing a specialist in configuring IIS.

I did evrything you said (at least I think so) but I have a 404.17 - Not found error when calling the phpinfo.php page.

Detail error should be something like "aked content seems to be a script and won't be handled by the static file manager".
Sorry if that message seems weird but it is a translation as my system is in French.

Just for information the web site works correctly if I call an .htm or .aspx(.net) file.

If you have any hint...

Anonymous's picture

installed aid to server 2008 with iis 7

and got problems.
well, before I could run php for all sites. PHP had been installed manually form php distributive. but I couldn't run smarty.
Today I thought to implement Aid tool. First removed php and installed tool. The first strange thing I sat that it said me that Fast-CGI is not installed. It was! And offered use ISAPI. ok. Asked to direct all php sites. Directed.
In result now I can't run any site having error:
HTTP Error 404.2 - Not Found
The page you are requesting cannot be served because of the ISAPI and CGI Restriction list settings on the Web server.
•No handler mapping for this request was found. A feature may have to be installed.
•The Web service extension for the requested resource is not enabled on the server.
•The mapping for the extension points to the incorrect location.
•The extension was misspelled in the browser or the Web server.

Checked according these directions. Everything looks ok but still nothing works. What to do now?

Help please!

Anonymous's picture

Almost working

Hi,
First of all, it's nice to see some dedicated person sharing his knowledge with the community. Great work.

Now with my problem.
I am using Windows XP Pro SP3
IIS 5.1 and PHP 5.2.6.6.

I got the PHPInfo.php working fine.
But when I call a .php page from a button, only the code of the .php appears. I have been working for the last 2 days on this problem, but can't seem to find the solution. I checked, double checked and triple checked everything, uninstall IIS and PHP. I did the reinstall to get the same result.

I also must say that I tried to install php 5.2.6.6 with the Apache 2.2 before but had similar problem. The only difference is that it prompted me to download or save the file instead.

Any thought about this ?
Thank you for reading this.

Pierre

Anonymous's picture

Almost working part 2

Hello again,

Well I think I have the solution to my problem. Would like your advice if it is normal.

When I access my file like this (http://localhost/Exercice1PHP.html) and click on the cmd button everything works fine but when the page is accessed like this (C:\Inetpub\wwwroot\Exercice1PHP.html)this is when I get this:


Le Garage de Bob - Résultats de la commande

Le garage de Bob

Résultats de la commande

echo '

Commande traitée.';
?>


as a result.

So, is it right to say that when working on the local server, the address always has to start with HTTP://localhost/ or HTTP://127.0.0.1/ ?

Hope to hear from you soon
Best regards,

Pierre

Brashquido's picture

Hi Pierre, This is actually

Hi Pierre,

This is actually quite a common issue. PHP is an interpreted script, meaning it must be proceesed by either PHP CLI or a webserver configured to process PHP content into a format that can be rendered by your browser. When you access your PHP scripts locally using http://localhost or http://127.0.0.1 you are invoking your locally installed webserver to proccess the requested content. When you try and access these scripts directly (i.e C:\Inetpub\wwwroot\Exercice1PHP.html) then you bypass your webserver and the PHP script is not executed.
----------------
Dominic Ryan
5 x Microsoft IIS MVP, MCSE, MCSA
IIS Aid owner/webmaster

Anonymous's picture

Directories

So if I want to work on more than one project, how do I manage my files. I tried to create directories, but the page pages won't show at all. I have the HTTP 404 error(can't findthe page). Exemple http://localhost/PHP/chapitre2/orderform.html

But when I but the page directly in the wwwroot folder like this http://localhost/orderform.html it is working fine.

Is there a way I can use so I don't put all my files in the same directory?

Thanks again for your assistance. greatly appreciated

Pierre

Brashquido's picture

404 could mean permissions

WHen you've confirmed that the files are definately there and are sure the path is correct, then a 404 error usually translates to there being a dile permissions issue. Ensure all you web files have at least NTFS read permissions to your IIS user account (usually IUSR_COMPUTERNAME).

----------------
Dominic Ryan
5 x Microsoft IIS MVP, MCSE, MCSA
IIS Aid owner/webmaster

Anonymous's picture

WHen you've confirmed that

WHen you've confirmed that the files are definately there and are sure the path is correct, then a 404 error usually translates to there being a dile permissions issue. Ensure all you web files have at least NTFS read permissions to your IIS user account (usually IUSR_COMPUTERNAME).

I have tried and couldn't get it working. Any other ideas ?
Would the fact that I have Visual Studio.Net 2008 installed be the cause as it also use IIS.