Setup Virtual host in Wamp Server


I have seen lot of developers working with wamp server will come up with the relative path problem

The best solution for the relative path problem is Creating virtual host.

Here are the procedures to setup virtual host in your wamp server

There are two files involved:

– hosts (this file is in the c:\windows\system32\drivers\etc\ folder)
– httpd.conf (this is in your Apache install’s ‘conf’ folder – mine is c:\wamp\Apache2\conf\httpd.conf)

When you open the “hosts” file, you will see this line at the bottom:

127.0.0.1 localhost

All you do is make another entry underneath it for your client site:

127.0.0.1 myclient.local (Use whatever extension you want (ex: .local))

…and save the file. You can make as many as you want for as many clients as you want. Just keep adding more lines like that last one. Basically what happens is when you type ‘myclient.local’ into a browser now, windows will check the ‘hosts’ file before checking the internet.

Now you need to open the httpd.conf file and add a couple things.

#NameVirtualHost *:80

…then add some crap underneath it to reroute ports and whatnot. If you’re in the same boat as me, this doesn’t work because ‘#NameVirtualHost *:80′ is not in my httpd.conf file.

Here’s what I did instead. Underneath ‘DocumentRoot “c:/wamp/www”‘ add this chunk of code:

NameVirtualHost 127.0.0.1

<VirtualHost 127.0.0.1>

ServerName localhost

DocumentRoot “C:\wamp\www”

<!–VirtualHost>

…then underneath that add this chunk:

<VirtualHost 127.0.0.1>

ServerName myclient.local

DocumentRoot “C:\wamp\www\Clients\MyClient”

</VirtualHost>

…obviously you’ll need to modify the code a bit to match the server name with the one from your ‘hosts’ file and the DocumentRoot with your client’s file path.
But that’s basically it. The problem you have now is that when you try and access your files from another computer on your local network,
the sites somehow revert back to not liking absolute paths.

Advertisements
About

Working For Cause Not For Applause

Tagged with: , , , ,
Posted in Drupal, PHP

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s

%d bloggers like this: