Setting Up a Virtual Host on WAMP

One of the biggest pains about developing on a local server setup like WAMP is that the root filepaths are different when you go live. To get around this I always set up a virtual host so that my development url can be something like, http://myapplication.dev/. Here’s how to do it on Wampserver 2.5. This is tailored for Laravel but you can adjust it as needed.

First, go into the WAMP menu under the Apache section, open up httpd.conf. Go all the way to the bottom and put in this:

<virtualhost *:80="">
     DocumentRoot "c:/wamp/www"
     ServerName localhost
     ServerAlias localhost
     <Directory  "c:/wamp/www">
        Options Indexes FollowSymLinks MultiViews
    	AllowOverride all
    	Allow from all
 	Require local
     
 </virtualhost>

This will be your base virtual host. Then you just add the specific ones you want after that. It’s just a matter of copying and pasting to add a new one.

<virtualhost *:80="">
 DocumentRoot "c:/wamp/www/myapp/public"
 ServerName myapp.dev
  <Directory  "c:/wamp/www/myapp/public">
    Options Indexes FollowSymLinks MultiViews
	AllowOverride all
	Allow from all
	Require local
 
</virtualhost>

Changing “myapp” to the name of the directory of your project, of course. Next, open up your hosts file (I create a shortcut on my desktop for easy access.) On my machine (Windows 7) it’s in C:\Windows\System32\drivers\etc. Add this line to the end:

127.0.0.1 myapp.dev

If you haven’t already, you will also need to enable virtual hosts by uncommenting this line in your httpd.conf file:

Include conf/extra/httpd-vhosts.conf

Restart WAMP and you should now be able to access it at http://myapp.dev. The long explaination is here.

Leave a Reply

Your email address will not be published. Required fields are marked *