Installing Apache, PHP, MySQL, phpMyAdmin in Windows XP/Vista

It would be great to have a server of your own. If you own a computer, you can turn it into a server by installing some software. Though how that extends the capability of your computer is a different matter altogether.
If you ever plan to go dynamic with your website, you would need a server to handle the backend. Now, Windows comes with its own server called Internet Information Services (IIS) but take my advice and get yourself Apache due to its high configurability and open support. In addition to setting up the server, I will also help you setup PHP, a dynamic server side scripting language; MySQL, a database backend for your website; PHPMyAdmin, to avoid the command line interface of MySQL and a few tweaks for a freshly installed server!
When I tried my hand at setting up all the above software for the first time, I admit I was totally flabbergasted! It would simply not run at all! So, if you find yourself in the same situation, don’t worry, you are not alone. And that’s the reason why I am writing this guide after all! There are alternatives like XAMP which allow you to setup everything together which makes it less of a hassle to setup the server, but I recommend installing each software individually to get an idea of how the server actually works. Setting up a server on Windows Vista presents some new challenge than when installing on Windows XP. The basic issue is of permissions. I recommend turning off User Account Control (UAC) temporarily for the installation of the server, though it is not necessary.
Step 1: Download the Apache2.2 Server and install it
- Downloading is not that simple. You will need an installer file (.msi) and not a source file (usually .zip). Go for the Apache2.2 series instead of Apache2 as they are latest.
- Look for a section heading that looks like “Apache HTTP Server 2.2.x is the best available version”. Click on the “Other Files” link inside that section. Now you would be taken to a tree-like list. Click on “Binaries/” folder. Select your Operating System folder, in this case “win32/”.
- There will be a list of various .msi files. If the latest version is 2.2.6, then download the file named “apache_2.2.6-win32-x86-no_ssl.msi”.
- Finally install the server. Put “localhost” in the Network Domain and the Server Name. Remember to install Apache as a service. Keep all the default settings if you don’t understand any of them and the software will be installed. The default location is “C:\Program Files\Apache Group\”
- You can verify your installation by opening your regular browser and typing “localhost” in the address bar. A welcome page should be displayed if everything went alright.
- Remember that you need to place your website in the “C:\Program Files\Apache Software Foundation\Apache2.2\htdocs” folder. This location is represented by the “localhost” keyword in the address bar of your browser.
Unless an error pops up, the installation should work without any extra steps. If the Apache monitor is not showing up in the task bar, just restart the system and it should come up. If for some reason the verification fails, ensure that the apache service is running by executing “services.msc” in the RUN window (Windows Key + R).
Please note that executing the Start, Stop and Restart batches directly doesn’t work (At least it didn’t for me!). You should right-click and select Run as Administrator from the context menu in Windows Vista.
Step 2: Download PHP5 and install it
- Download the latest version of PHP from http://www.php.net/downloads.php. Again remember to download the Windows Binaries Installer file rather than Complete Source Code. As of now, the latest version is 5.2.5.
- Ensure that you select the correct web server when the question pops up. In this case, select Apache 2.2.x.
- When it asks for the configuration directory of the Apache server, select the conf directory within the Apache folder.
- Optionally, you can install every extension listed, but all of them won’t be activated after the installation. Unless you have a specific purpose, select the gd, mbstring and mysql extension only.
Step 3: A necessary manual step for successful PHP Installation
- Since PHP is installed as an Apache module, the configuration file needs to be set. I am not sure why but the installer fails to configure the httpd.conf file completely. So open the httpd.conf file in the Apache installation directory and go to the bottom of the file. You should see the following lines at the end of the file. The path may differ according to your specification during installation.
- There is another very important line which needs to be added at a specific location in the configuration file which the installer doesn’t do itself. Search for <IfModule mime_module>…</IfModule> in the file and add the following line anywhere between the construct.
- Restart Apache through the monitor or selecting it from Start -> All Programs -> Apahce HTTP Server 2.2.x -> Control Apache Server -> Restart.
- Now PHP has been installed completely and we need to test and verify it. That’s the next step.
# PHP Installer EDIT
LoadModule php5_module “C:/program files/php/php5apache2_2.dll”
PHPIniDir “C:/program files/php/”
# PHP Installer EDIT ends
AddType application/x-httpd-php .php
Step 4: Verify PHP Installation
- Create a file named info.php (or anything you like!) with the following contents and put it in the htdocs folder of the Apache installation.
- Run the file in the browser (”http://localhost/info.php”) and you should get a detailed view of your PHP installation.
- If instead of displaying details of PHP, you get the contents of the file on the screen, then PHP has not been recognized by Apache. Ensure that you have configured the httpd.conf file correctly. On the other hand, if nothing is displayed on the screen, then make sure Apache is restarted without any configuration error.
- If you took care of all the steps, then PHP should be recognized successfully. Congratulate yourself! The job is half done!
<?php
phpinfo();
?>
Step 5: Download MySQL5 and install it.
- Many people have difficulty in setting up MySQL on the server, but follow these steps and you will be fine.
- Download MySQL Community Server 5.0 at http://dev.mysql.com/downloads/mysql/5.0.html. Remember to select the Windows edition. You might download either “Windows Essentials” or “Windows ZIP/Setup.EXE” according to your needs.
- After installation, a MySQL Server Instance Config Wizard will pop up with various options. Don’t bother about them since the defaults will work fine! Remember to choose a good root password.
- The php.ini file will be configured automatically so you need not worry about that. Still ensure that the following lines are present in the php.ini file at different places. (The path can be different accordingly.)
- This is the most important step for MySQL to be recognized in PHP. Navigate to PHP Installation directory and copy libmysql.dll file and paste it in C:\Windows\ directory.
- Restart Apache! This is must!
extension_dir =”C:\Program Files\PHP\ext”
extension=php_mysql.dll
Step 6: Verify MySQL as well
- Run the info.php file you created for verifying PHP again in the browser. Scroll down and check whether a MySQL subsection has appeared or not. If you see a MySQL headed subsection, MySQL has been successfully setup on your server.
- If not, then check whether php_mysql.dll file is present in the ext folder of PHP Installation directory. If not, then you would have to install PHP again. Also make sure you copied the libmysql.dll file in the Windows directory.
- At this stage, you should have a complete server ready to serve your MySQL database backed & PHP powered website with ease. Believe me you have done a commendable job, so pat yourself! Celebrate! If you maintain a blog like me, then write about it!
Step 6: Get phpMyAdmin up and away!
- Handling MySQL from a command line can be a real pain in the stomach (ouch!). Unless you are a system administrator or something, you definitely need a good interface to work with MySQL. PHPMyAdmin makes it easy even for a newbie. This software is used by many web hosts as well, so it is better to get acquainted with it.
- Download the latest version of phpMyAdmin from http://www.phpmyadmin.net/home_page/downloads.php. Select the english.zip binary from the list.
- Copy the downloaded folder in the htdocs directory of Apache Installation. Preferably rename it to something simple like pma or anything you feel like.
- Create a folder called config (no options here!) in the folder you just renamed.
- phpMyAdmin will need a database for activation of advanced features. So start the MySQL from Start -> All Programs -> MySQL -> MySQL Command Line Client. Enter the root password which you setup while installing MySQL. Now type out the following command as it is. (Choose any database name of your liking.)
- Type exit; to quit the client.
- Now run http://localhost/pma/scripts/setup.php in the browser to configure phpMyAdmin. You will see a page with lots of buttons. But don’t worry you need not press everyone of them!
- First of all, click on the Add button under the Server section. You will be taken to a new page with many things to fill. If you are setting up a local server on your personal computer, then fill out the following fields only with the specified data.
- Now click on Add and the server will be added to the list. Now click on Display under the Configuration section. The contents of config.inc.php file will be displayed. Then click on Save and Load.
- Copy the config.inc.php file from config directory to the pma folder (your phpMyAdmin directory).
- Now run http://localhost/pma/index.php to start working with phpMyAdmin and maintaining your server!
- Remember that this is the least secure phpMyAdmin setup. Use it only on a development server. To make it more secure, read my article on Securing phpMyAdmin on an Apache Server.
create database database-name;
Server hostname: localhost
Connection type: TCP
PHP extension to use: mysql
Authentication type: config
User for config auth: root
Password for config auth: ********
phpMyAdmin control user: root
phpMyAdmin control user password: ********
phpMyAdmin database for advanced features: database-name you created just now
Step 7: Tweak your server.
I will list here a few small changes that you can do to your server configuration file for a better server experience. It is not necessary and your server will run fine without these changes as well but sooner or later you will have to make these changes! If you are planning to run content management systems like Wordpress, Drupal, TypePad etc., you definitely need to make these alterations.
Setup a default file for directory request
- Look for the following line in the httpd.conf configuration file.
- Change it to the following:
- Restart Apache. If you want any other file to be called on directory request then change it accordingly. This is helpful as http://localhost/pma/ will be same as http://localhost/pma/index.php. Very useful for CMS and in general use.
DirectoryIndex index.html
DirectoryIndex index.php index.html
Enable mod_rewrite feature of Apache (For advanced users only)
- mod_rewrite is a very important tool for server administrators. Most of the CMS use them today. They make your URL very user-friendly and search engine friendly as well!
- Look for the following line in the httpd.conf configuration file.
- Remove the hash sign(’#') in front of the line to uncomment it.
- Look for the block <Directory “C:/Program Files/Apache Software Foundation/Apache2.2/htdocs”>…</Directory> in the file. Inside it look for the following lines:
- Replace the last line with the following:
- Restart Apache. Now you can take advantage of the powerful mod_rewrite tool to make search engine friendly websites!
#LoadModule rewrite_module modules/mod_rewrite.so
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be “All”, “None”, or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride None
AllowOverride All
That’s all there is to convert your personal computer into a local server! Have a good time with your websites and any other thing you might want to do with your server! I hope this guide will make the task of setting up a server a friendly process!
Be up-to-date with your computer. Subscribe to our RSS feed!
If you enjoyed the post, please digg it, stumble it or delicious it.


Subscribe to XSRealities via RSS

Thanks for the article. I followed the instructions “a la lettre” and was faced with an unknown error that I can’t figure out: I get the “It Works” message, the Apache icon is on my taskbar and the service is running. I then place the info.php file in the htdocs folder and run it… Error file not found…
I also have an issue with the httpd.conf file.. your example “at the end of the file” is nowhere to be found.
PLease help as I can’t think of any way to fix this problem and get at least my info.php page running.
I have Vista.
Thanks
Olivier
Hi Olivier!
Did PHP install without any error? Since the required lines are not present at the end of httpd.conf file, it seems PHP is not installed correctly… Reinstall PHP.
The “file not found” error will also disappear once PHP is installed correctly.
Best Luck!