As the name implies, virtual hosting means you can virtually host different sites. Instead of you being stuck with localhost preceding every site, you can easily work with a virtual host such as mySite.local/. Cool right? So how exactly can this be done? This solution allows you to host multiple virtual hosts on your wamp server.
After installing Wamp Server on your computer system, you can place all your sites in the www folder and preview them on a web page using localhost/mySite. But if you would like to have a local URL of your own, follow the following steps
Step 1: Edit the Windows hosts file (directory is C:\Windows\System32\drivers\etc\hosts using your favorite text editor (I used Notepad). If you are using Windows Vista or 7, ensure that you open Notepad with administrator privilages, else you would not be able to save changes. To open with administrator privileges, search for your text editor (in this case notepad) from your start menu. Right click it and select Run as administrator. Add a line 127.0.0.1 your-local-domain. You can out any name in place of your-local-domain. Your file should look like this. Save and continue to step 2.
Step 2: Next, open the httpd.conf file found in C:\wamp\bin\apache\apache2.2.11\conf (note that the version number of apache may be different depending on your installation, i.e. 2.2.11). Scroll towards the bottom and look for the line that says #Include conf/extra/httpd-vhosts.conf says remove the comment (i.e. # sign).
Step 3: Open the httpd-vhosts.conf file found in C:\wamp\bin\apache\apache2.2.11\conf\extras using your text editor. Scroll to the bottom and include the following code lines shown below. The first module is needed to preserve the http://localhost while the second one is for each subdomain you would like to create. Note the line that says DocumentRoot. You should include the directory of your subdomain. If you choose you file to be within C:\wamp\www\your-local-domain, then you can omit the whole <directory>
<virtualhost *:80>
ServerAdmin webmaster@localhost
DocumentRoot "c:/wamp/www"
ServerName localhost
ErrorLog "logs/localhost-error.log"
CustomLog "logs/localhost-access.log" common
</virtualhost>
</virtualhost>
<virtualhost *:80>
ServerAdmin webmaster@localhost
DocumentRoot "c:/Users/marf/Projects/your local folder/html"
ServerName your-local-domain
ErrorLog "logs/your_own-error.log"
CustomLog "logs/your_own-access.log" common
<directory "c:/Users/tobaniyi/Projects/your_local_folder/html"> </directory>
Options Indexes FollowSymLinks
AllowOverride all
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
</virtualhost>
Save all changes and restart the apache server. With these steps, you should have your sub-domain fully functional.


No comments:
Post a Comment