Setting up Apache with IIS and running PHP on both

IIS, PHP 4.5.2009 No Comments

Setting up Apache with IIS (and PHP on both)

Recently I’ve been working on a project in PHP since it required true URL rewriting which just is not available in the windows environment currently. This required the installation of Apache and it’s wonderful mod_rewrite module which does all the wonderful URL rewriting stuff. I ran into a bunch of issues which I’ll cover here to help anyone else trying to setup Apache with IIS.

  1. First you need to download the latest Apache windows binaries at http://www.apache.org
  2. Install Apache, select the first option in the wizard which is to install on port 80, as a service. We know that IIS is already running on port 80, but we can make changes to the apache config latter on.
  3. Now that apache is installed, go to the folder that it was installed to. On my machine it was c:\program files\apache software foundation\apache2.2
  4. Go to the /conf folder and open the httpd.conf file (may be named differently in the future or older versions)
  5. Find the line “Listen 80″ and change to “Listen 8080″. Save the file.
  6. Open a browser and try “127.0.0.1:8080″ and you should get a page that says “It works” (that page is the apache default page)

Now, the main reason for installing apache is to run PHP with it. If you haven’t setup PHP to work with IIS you can just install and everything is fine. If you do have PHP working with IIS, then there are a few more steps you need to do.

  1. Find that httpd.conf file again and find the lines that begin with “AllowOverride” and change to “AllowOverride All”
  2. Find the line that begins with “ScriptAlias /cgi-bin/” Add AFTER this

    ScriptAlias /php/ “c:/Program Files/PHP/”
    AddType application/x-httpd-php .php
    Action application/x-httpd-php “/php/php.exe”

  3. Find the line that begins with DirectoryIndex and add at the end of the line “, index.php”
  4. Save the httpd.conf file.
  5. Now go to your PHP directory and ensure the following files are in the root directory
    php5apache2_2.dll
    php5apache2_2_filter.dll
    php5apache_hooks.dll

    If they are not there, download the PHP manual installation files from the PHP site.

  6. Open the php.ini file and find the line that starts with “open_basedir”. Make sure this is commented out as this line restricts the operation of PHP to a certain directory.
  7. Save the file and exit. Now create a test file in your htdocs folder of apache called test.php and just add the lines ““. Open a browser and go to “127.0.0.1:8080/test.php” and see if the php info stuff shows up.

That’s it, you should now be able to run PHP in both IIS and through Apache on port 8080. Please leave a comment if there were any issues with this tutorial. Thanks!

Leave a Reply