Installing Apache alongside IIS for Zend PHP Framework

After deciding to experiment with the Zend PHP Framework for web application development, I needed to install Apache on a local machine for development. I’m a novice when it comes to Web Server configuration / installation, but after reading the installation would take 15-20 minutes, I started feeling pretty dumb after a few hours of searching Google and still getting either nothing at all, or error messages.

The setup I had before the installation was XP Professional, with IIS already installed. Also there were PHP5 and MySQL 5.0.41

To try and save you a few hours you’ll never get back, here’s how I managed to get Apache / PHP / Zend up and running:

  1. Download the Apache installer (the .msi file)
  2. Install Apache using the installer and fill in the options you need
  3. Modify the httpd.conf file as follows:
    1. To get it to work with IIS you need to change the port to something other than 80 (which is the one IIS listens to by default). To do this you can search for Listen, and change the line to:
      Listen 8080 (This means that the web root document on the Apache server is accessed through http://127.0.0.1:8080).
    2. Search for rewrite_module and uncomment the line:
      LoadModule rewrite_module modules/mod_rewrite.so
      (This module is used by the Zend Framework to rewrite URLs)
    3. At the end of the LoadModule statements, add the line:
      LoadModule php5_module "C:/Program Files/PHP/php5apache2_2.dll"
    4. Search for DirectoryIndex and change it to:
      DirectoryIndex index.html index.html.var index.php
    5. At the end of the AddType statements, add in the lines:
      AddType application/x-httpd-php .php AddType application/x-httpd-php .phtml

It was around here that I ran into problems….

It seems obvious now (!), but even though you have PHP installed for IIS, it won’t work on Apache unless you reinstall the parts you need (…as I said, a novice). When I originally installed PHP, I downloaded a .msi file (php-5.2.3-win32-installer.msi) – so go back to where that’s saved, double click on it, and select “Next”, then “Change” and you see four collapsible lists.

From here, go into “Extensions” and select “PDO” (PHP Data Objects Support – which Zend uses)… that was figured out after some time searching for an error that said: “Uncaught exception ‘Zend_Db_Adapter_Exception’ with message ‘The PDO extension is required for this adapter but the extension is not loaded’.

Under the “Web Server Setup” list choose the Apache Version that you need (I had the most recent version, so I selected “Apache 2.2.x”).

I found that when viewing the site in Firefox, I got a “Cannot Connect to Server” when trying to view PHP files or sub-directories before the installation was set up correctly. You can also use the “Start Apache in Console” command in the Start Menu (Start >> All Programs >> Apache HTTP Server >> Control Apache >> Start Apache in Console) to see if there are errors; if there aren’t, you’ll get a blank screen, otherwise the error will be displayed.

After this, it was just a matter of following the Zend Framework installation instructions, and it was up and running…

Some tutorials that saved me even more time doing this were:
http://tanguay.info/web/tutorial.php?idCode=phpDevelopment

If there are any updates to the configuration as I experiment with Zend, I’ll add them in here, or drop them into a new post….