Thursday, March 25, 2010

Setting up a local virtual server in Linux

If you're like me, then you design web sites on your local server before pushing the update out to the site.  I tend to take and make my local server http://domain/.  This allows me to fully test and run the site just as it runs on the server, but without the lag/extra steps with working on the server itself, not to mention my changes don't effect the visitor's experience until I push the update.

To do this, go to:


It will look like this:       localhost

You need to update this file so your browser knows to look locally for the domain.  Add a line for your domain name...       domain
OR       domain2.loc

Next you need to tell apache about your new domain. Go to /etc/apache2/sites-available/ and create a file for your new domain. Since my new domain is literally "domain" that's what I will call my file, with no file extension. Within that file I'll put this....

NameVirtualHost domain:80

<VirtualHost domain:80>
ServerName domain
DocumentRoot /var/www/domain/

Once you've got this setup you're good to go. All you need to do is restart apache...

/etc/init.d/apache2 restart

Now I can access this local domain by simply typing http://domain/ and it won't effect the users browsing my site.

No comments:

Post a Comment