First, we need to install apache's mod vhost. You can do this via:
sudo apt-get install libapache2-mod-vhost-hash-alias
sudo mv /etc/apache/mods-available/vhost_alias.load /etc/apache/mods-enabled/
Now, we need to configure apache to make use of the vhost module. Let's start by creating the vhost directory:
sudo mkdir /var/www/vhosts
sudo chown www-data www-data /var/www/vhosts
And now add this at the end of our /etc/apache2/apache2.conf file:
#vhosts
NameVirtualHost *:80
UseCanonicalName Off
DocumentRoot /var/www/vhosts
Options -Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from all
VirtualDocumentRoot /var/www/vhosts/%0.0
This essentially says that any domain that we host locally will reside at /var/ www/vhosts/domain. You can modify the virtual document root as needed to add a public_html or htdocs directory if you wish. Make sure to cycle apache with:
sudo apache2ctl -k graceful
Apache should be running well enough now and you can testing this by creating a test domain directory (and adding a simple index.html file) and modifying your /etc/hosts file to point the test domain to 127.0.0.1. This works well enough on it's own but we don't want to add to the hosts file for every site we create. As such, we're going to install dnsmasq and route a full block of domains for our usage.
First off, let's install dnsmasq:
sudo apt-get install dnsmasq
Once installed, you will need to modify /etc/dnsmasq.conf and replace
#listen-address=
with:
listen-address=127.0.0.1
and at the end of the file add:
address=/dev/127.0.0.1
This will point all .dev domains to your local development environment. You can specify any extension you wish or a full domain (address=/example.com/127.0.0.1).
Now we need to modify /etc/dhcp3/dhclient.conf and uncomment the following line by removing the '#':
address=/dev/127.0.0.1
Restart your dnsmasq service with:
sudo /etc/init.d/dnsmasq restart
And you should be able to create new folders with the names site.dev in your /var/www/vhosts folder and they will be available at the domain in your browser. If you use an eclipse based editor you can change your workspace to sit in /var/www/vhosts and whenever you create a new project just name it site.dev and it will be instantly available.
Originally published at http://www.lamptricks.com/2007/11/25/local-development-and-hosts-on-ubuntu/
Published by Håvard Hegtun
An American immigrant born and raised in Norway. Now living in Southern California. View profile
- Top 5 Tips on How to Choose a Domain NameYou've got a great idea to publish on the Internet. It may be a new product, a cool business, or a unique insight on a specific topic, or just a desire to immortalize yourself via a blog on the world wide web. Whateve...
Domain Registry of America: Domain Name HijackingI keep getting these letters in the mail at least once every other week notifying me that the domain name that I registered is about to expire.
NYC's Mayo Mike Bloomberg: Domain Name Squasher?New York City Mayor Mike Bloomberg has changed his registration from Republican to Independent. Some think it's a prelude to a run for President. Based on my client's experien...
How I Got a Free Domain Name: You Can Too!DomainLagoon really does give out free domain names, I got one myself! I buy domain names sometimes, when I think of a good idea for one or I come up with an idea for a website...
- Creating a Windows-Free Web Design Enviroment
- How to Modify the Hosts File to Block Bad IPs (RIAA / MPAA Etc)
- Top 5 Reasons Why NOT to Use a WYSIWYG Editor for Web Development
- How to Get Started in Web Development
- How to Access FTP Servers from Nautilus in Ubuntu Linux
- Facts About Open Source Software Development
- Basics of Web Development



