Tutorial for hassle free Apache / PHP / MySQL installation.

Hello, I decided to write this post since I knew few people who are not be able to getaway with the installation since they are too new to this world!So to make their/your installation trouble free i’d to write this guide 🙂

This method works well with all Windows PC. Hope this helps people.!

Install Apache

Apache is most trusted web server that suits for the installation of PHP on your machine. Apache is an open source web server, which has captured almost 80% of web server market today.

Download latest version of apache windows binary installation from http://httpd.apache.org/download.cgi. The latest version that is available today is Win32 Binary (MSI Installer): apache_2.2.3-win32-x86-no_ssl.msi

Before installing make sure to disable IIS web server if running. Since it might conflict with the default HTTP port 80, in which apache runs by default.

Now let us install Apache web server into your PC. Execute the previously downloaded apache installation file which is standard Windows installation file and thus very straightforward. Just fill in the required information on screen and end the installation.

Once you have done your apache installation try visiting http://localhost; you should get an apache test page. If you’re done with successful test page, you’re ready to proceed to next step.

Install PHP

Congrats! You’ve made a wise decision to install PHP, a leading open source web programming language.

Now visit http://www.php.net/downloads.php to download latest version of PHP. Download the latest available windows binary version in ZIP format.

Once download is complete; unzip the package into a directory preferably in root drive say C:\PHP. Now you’ve to move the file named “phpXts.dll” from the PHP installation directory to Windows directory (C:\Windows or C:\winnt depending upon your OS version); X stands for the version of PHP being installed. Make an entry to C:\PHP in the PATH environment variable.

Configuring PHP

Now you need to tell apache web server what to do when it encounters PHP file. To make this work we need to make some modification in both apache and PHP configuration files.

Before doing any modification to configuration files, create a directory where you’re going to place the web application. Say C:\www

First rename the php.ini-dist to php.ini in PHP installation directory, in our case C:\PHP. Then modify the following in php.ini
doc_root = “c:\www”
extension_dir = “C:\php\ext

Change the location if you’ve installed in different location.

Note: Use backslashes while you specify any path in configuration files.

Now open httpd.conf file available in apache configuration directory (generally C:\Program Files\Apache Group\Apache2\conf\). Edit the DocumentRoot entry to DocumentRoot “C:/www”

Then change the Directory Entry as . Add the following entry into the configuration file as well before AddHandler section (do a search for “AddHandler” for find the position fast).

ScriptAlias /php/ “c:/php/”
AddType application/x-httpd-php .php .php5
Action application/x-httpd-php “/php/php-cgi.exe” # if PHP5
Action application/x-httpd-php “/php/php.exe” # if PHP4
SetEnv PHPRC “C:/php”

Finally add index.php to the DirectoryIndex entry as well like “DirectoryIndex index.html index.html.var index.php”

Now you’re ready before testing the PHP; you need to restart Apache web server to effect the changes.

Testing PHP

Create a file named phpinfo.php in C:\www or whether you configured as home directory. In phpinfo.php add “ and save.

Now point your browser to http://localhost/phpinfo.php and you should be able to see the PHP environmental variables displayed. If you’ve not seen that page you need to review the installation process again, you might have missed or went wrong in any of the above steps 🙂

Install MySQL

Now we’re almost in the final stage, we need to prepare a backend so that our web applications can make use of it. MySQL is the best choice to combine with apache and php.

Download the latest version of MySQL from http://dev.mysql.com/downloads. You’ve to download the latest available stable Window MySQL into your PC.

Once download is complete, double click on the MSI installation file, which you have just downloaded. Follow the onscreen instruction to complete the installation. Skip the sign up section and make sure you check “configure the MySQL Server now” option.

Now you will get a configuration dialog box, which can be configured easily by reading the instruction. Make sure “Install As Windows Service” is checked in the configuration page. Then define your admin password as well.

Setting up MySQL

First of all, check the c:\php directory and make sure that the files libmysqli.dll and php_mysqli.dll are both there. If they are not there, check the c:\php\ext directory and copy the files into c:\php

Then open up the file c:\php\php.ini in your editor and ADD the line extension=php_mysqli.dll

Now restart the apache web server to reflect the changes made.

Create a php file and test the mysql functions to connect to the database. Make sure your MySQL server running before executing the php program.

You can use PHPMyAdmin (www.phpmyadmin.net/) to manage your MySQL database through easy to use web interface.

Learning PHP

The complete PHP reference manual can be obtained from the php website itself. You can start learning other basic books to start off with PHP!!!

Have fun with php!!