Tuesday, July 10, 2007

Installing PHP 5 & Apache 2 on Windows Vista

I wanted to use IIS 7 with PHP, but just couldn't get it right. I tried all solutions, installed the ISAPI extension, run the mapping script - zitto. After hours of trying I gave up. Screw it. 

So I decided to install Apache. Thinking it was an easy task... but no sir, it was equally time consuming. I just don't understand why. After much tinkering, finally got it to run. 

No, I refuse to use those all-in-one installers. No WAMP, XAMPP and etc for me.

Before you begin, this is a good site to refer to http://wamp.corephp.co.uk/index.php.

Who those who might be in the same predicament, here is the steps that I took:-

Step 1: Download PHP and Apache
Step 2: Install
  • Unzip the PHP zip file. You can store is anywhere, but the usual practise is C:\php. But its up to you. 
  • Once done, now run Apache setup file. For installation steps - http://wamp.corephp.co.uk/step_07.php 
  • For Apache, you can run it as service using port 80 or via console using port 8080. Its up to you. I am using console since I still need the stupid IIS to run .Net. 
Step 3: Configure
  • Now, go open the C:\php folder. Rename the file php.ini-recommended to php.ini. Open the file. Look for the value "doc_root". After the "=" sign, type this "C:\Program Files\Apache Software Foundation\Apache2.2\htdocs". This will tell PHP to look for the web files at the mentioned folder. You can always change the path. 
  • Now save the file. You can do the other tweaking later on.
  • Open your Windows Explorer to "C:\Program Files\Apache Software Foundation\Apache2.2\conf\default". 
  • Rename the file httpd-win.conf to httpd.conf. Open the file in notepad or any editor of your choice.
  • Now comes the part that caused me the most headache. Telling Apache to parse PHP. 
  • Look for within .conf file for DSO. Under it there will be a bunch LoadModule statements. Just on top of the first statement, type this
  • # PHP5
    LoadModule php5_module "c:/php/php5apache2_2.dll"
    PHPIniDir "C:/php"

    AddType application/x-httpd-php .php
    AddType application/x-httpd-php-source .phps
  • Next look for the value DocumentRoot. Make sure it looks like this - DocumentRoot "C:/Program Files/Apache Software Foundation/Apache2.2/htdocs"
  • Now save the file and copy the file out to "C:\Program Files\Apache Software Foundation\Apache2.2\conf" folder level. 
  • Almost there... now depending on your Apache setup earlier, try this http://localhost/ or http://localhost:8080/.  You should be welcomed with "It Works!" message. 
  • Make sure Apache is running. If your running console, use the CMD command and "cd" to "C:\Program Files\Apache Software Foundation\Apache2.2\bin" and type httpd. Don't close the windows, its your web server running!
  • Now the acid test. Create a php file with the following syntax

    <?php

    phpinfo();

    ?>

    Save it as phpinfo.php in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs. 
  • Now run again http://localhost/phpinfo.php or http://localhost:8080/phpinfo.php.
  • You should be able to see all the PHP config information. 
  • If you don't, then probably there is some PHP or Apache config error. Good luck!

No comments: