I’m back after my vacation of Dashain. This ain’t the first article about installing Apache under Windows. But I’ve put it here to ease the life of beginner developers. Without further ado, lets delve in.
Step 0
Installed OS is Windows XP.
The server package that we’re installing is WAMP5 1.7.0
Step 1
Download WAMP5 1.7.0 and Install it. (Note: If you already have installed older versions or other package like EasyPHP, then remember to backup your files first.)
I installed the WAMP5 in my D:\Server directory. So, the following tutorial will assume this as the main Server folder.
To test whether the server is installed properly, just type localhost in your browser’s window.
If the list of folder is shown, then server is working.
Step 2
Many of you might know that if we type localhost in the browser’s address bar, the list of the server root is listed. In this case, the folders of the directory D:/Server/www (Here, the folder D:/Server/www is our web-root folder.)
If you open the file named “hosts” at C:\WINDOWS\system32\drivers\etc in plain text editor like notepad or notepad++, you’ll notice the following line
127.0.0.1 localhost
Actually this line instructs the server to parse localhost to IP 127.0.0.1 (which is a local and free ip).
Just copy the line and paste it below like
127.0.0.1 localhost
127.0.0.1 www.mysite.sac
and save it.
Now you might be thinking that where is the settings defined to list the contents of web-root folder (in this case D:/Server/www) when we type localhost in the browser?
Well, this is defined in the file D:\Server\Apache2\conf\extra\httpd-vhosts.conf
Notice the block,
<VirtualHost *:80>
DocumentRoot E:/Server/www
ServerName localhost
</VirtualHost>
I’ll explain this in the following steps.
Step 3
Open up the configuration file of the Apache web server located at D:\Server\Apache2\conf\httpd.conf
Find the line: Include conf/extra/httpd-vhosts.conf
At the begining of this line, there might be a # symbol. Just delete that # symbol and save the httpd.conf file. (# stands for comment, so we’re just commenting out that line). If there ain’t any #, then just do nothing to this file.
Step 4
Open up the file E:\Server\Apache2\conf\extra\httpd-vhosts.conf
Find the line: NameVirtualHost *:80
Same as Step 3, just delete (uncomment) the # symbol at the begining of line.
Copy the block
<VirtualHost *:80>
DocumentRoot E:/Server/www
ServerName localhost
</VirtualHost>
and paste it below that block and change the values
<VirtualHost *:80>
DocumentRoot D:/Server/www/mysite
ServerName www.mysite.sac
</VirtualHost>
Create a folder named “mysite” at Web root (i.e. D:/Server/www in this case) and put some files there.
Save this file.
This block is called Virtual Host Directive.
The DocumentRoot defines the root folder for the ServerName (here, www.mysite.sac)
You can put any name and extension to it. I’ve used .sac
Just remember to match the exact ServerName defined in the VirtualHost directive and in hosts file at C:\WINDOWS\system32\drivers\etc
Step 5
Restart your WAMP Apache Server and type www.mysite.sac in the address bar of your browser.
If you see the contents of the folder “mysite”, then the installation is successful and its working. Enjoy! developing your projects with the feel of online development in an optimized approach.