Buy me a Beer
Web 2.0 Training
 
headermask image

Random Header :: Unpredictably Exciting

How to Install PHP, Apache and MySql on Windows.

I’ll try to keep it as simple as possible. So, to make PHP work you need to set up:

  • Database
  • PHP
  • Web Server

Install MySql

This is the easiest part. I recommend you install MySql5 using a simple and easy Windows installer (mysql.exe).

Install PHP 5

I recommend you install PHP 5.2.1 as it is the current stable version. There are two ways to do that:

  1. Install via windows installer (exe file).
  2. Unzip all the content in a folder (say C:/PHP5). I recommend you unzip the contents as it gives you better control.
  3. Open the PHP directory and find php.ini.recommended. Now rename it as php.ini and paste it in C:/Windows directory.

Install Web-Server

There are many popular Web-Servers, but I recommend Apache 2 . But why Apache 2 ? Well, explaining that is beyond the scope of this article but you can read that in my other post.

  1. Download the latest stable version of apache web server from www.apache.org.
  2. After installation, go to the apache installation directory and make a note of two very important directories:
    • apache/conf
      • This directory contains the file httpd.conf, which is required to edit and fine tune apache server.
    • apache/htdocs
      • This is the default root directory for the web server. Although it can be changed by editing httpd.conf file.
      • Download the latest stable version of apache web server from www.apache.org.
  3. You can install PHP as CGI and as Module in Apache. All you have to do is open httpd.conf in conf directory and add these lines:
  • PHP and Apache 2.0 as CGI
    • ScriptAlias /php/ "c:/php/"
      
      AddType application/x-httpd-php .php# For PHP 4
      
      Action application/x-httpd-php "/php/php.exe"
      
      # For PHP 5
      
      Action application/x-httpd-php "/php/php-cgi.exe"
  • PHP and Apache 2.0 as Module
    • # For PHP 4 do something like this:
      
      LoadModule php4_module "C:/PHP4/php4apache2.dll"
      
      # Don't forget to copy the php4apache2.dll file from the sapi directory!
      
      AddType application/x-httpd-php .php# For PHP 5 do something like this:
      
      LoadModule php5_module "C:/PHP5/php5apache2.dll"
      
      AddType application/x-httpd-php .php
      
      # configure the path to php.ini
      
      PHPIniDir "C:/Windows"

Great, you have now installed a web server, Database and PHP. Now lets test it.

  • Open your browser and type http://localhost or http://127.0.0.1 If you see an Apache welcome page then it means Web Server is installed successfully else try again.
  • Open htdocs or your root directory of web server and create a file info.php. write these three lines in it:
    < ?php
        phpinfo();
    ?>
  • Now run this file from your browser, like this http://localhost/info.php. If you see the detail information about php, then php is installed successfully else try again to install php.
  • Open php.ini in notepad and look for extension_dir. Put here the <path of php>/ext. for example extension_dir = “c:/php5/ext”
  • Now find ‘extension=php_mysql.dll” in php.ini and remove “;” (semi colon) from the start of its line. Now restart the Web Server to enable this extension.
  • Repeat the above step to enable any extension like this.
  • If you can find “mysql” in http://locahost/info.php then you have successfully installed the mysql extention else try again.

NOTE: If you face problem installing mysql or curl extension then, copy all the files form “<path>/php/ext/” folder to “C:/Windows and” “C:/Windows/System32″ folder. Even if it doesn’t work then replace the extensions with the latest versions.

Here are few common issues in installing few extensions and their solutions:

  1. MySql Extension:
    • Download mysql_extensions.zip and Unzip all the files into your “../php/ext/” folder. Then just restart Apache.
  2. CURL Extension:
    • Download curl_extensions.zip and Unzip all the files into your “../php/ext/” folder. Then just restart Apache.
  3. Oracle (OCI) Extension:
    • This part is little tricky. You need to install Oracle’s instant Client Package before you can enable OCI extension from php.ini. The complete step by step guide is provided in Oracle’s official site. View Instructions.


If you liked my post, feel free to subscribe to my rss feeds

One Trackback

  1. [...] How to Install PHP, Apache and MySql on Windows. [...]

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*