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 http://www.domain.com 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:

/etc/hosts/

It will look like this:


127.0.0.1       localhost

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

127.0.0.1       domain
OR
127.0.0.1       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/
</VirtualHost>

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