Before you do anything, back up your original config files. I used to just create a copy of the files with the suffix “.bak” (sudo cp example.conf example.conf.bak), which works, but creates a lot of clutter. Now I use a great little utility called etckeeper which automatically places all files in /etc under version control using Bazaar. It also automatically performs a commit each day if you forget to. You can get etckeeper by typing this in the terminal: sudo apt-get install etckeeper.
Update, 3/29/10
I just had to do this from scratch after a computer disaster, and I found an omission. Before you get started on this business you need to do what this post says:
http://www.likesalmondesign.com/use-your-users-public_html-directory-to-serve-webpages/
And we’re off
Now on to virtual hosts. The first thing you need to do is edit /etc/hosts so your computer knows where to look for your website:
- In the terminal, enter:
$ sudo gedit /etc/hosts - In gedit, add the following line to the hosts file:
127.0.0.1 mysite.dev- Note: you can use whatever name you want for your virtual hosted site. I like to use the suffix .dev because it won’t conflict with sites on the actual internet.
- Note: 127.0.0.1 is the same ip address that is assigned to localhost in that file. If yours is different, use that one.
Next add your site to /etc/apache2/sites-available/ and then link to that file in /etc/apache2/sites-enabled/:
- In the terminal, cd to
/etc/apache2/sites-available/ - Create a new file with:
$ sudo touch mysite.dev - Open that file in gedit:
$ sudo gedit mysite.dev - Add following to that file:
<VirtualHost *:80>
ServerName mysite.dev
ServerAlias mysite.dev
ServerAdmin myaddress@email.com
DocumentRoot /home/yourusername/public_html/mysite/
</VirtualHost>
Add a pseudo link to that file in /etc/apache2/sites-enabled/:
- cd over to
/etc/apache2/sites-enabled/ - In the terminal, enter:
$ sudo ln -s /etc/apache2/sites-enabled/mysite.dev mysite.dev- Note:
$ ln -s target linkname
- Note:
Finally, restart Apache:
- $ sudo service apache2 restart
- You’re done!
See! Not so bad…