To create a virtual site that answers to
http://mysite.localon your existing apache setup in Ubuntu, do the following:
First we need a directory to hold the html. It can be anywhere, but we will put it in /var next to the www folder that already exists for the default site. And we will add a test file to be served up:
sudo mkdir /var/www-mysite
sudo nano /var/www-mysite/index.html
Nano will open with a blank file. Type something like Testing 1,2,3 and then hit ctrl-x to exit and save. Next we need to make the virtual host configuration file to point to this directory:
sudo nano /etc/apache2/sites-available/mysite.local
This will open up a new mysite.local file for editing. Put the following in the new file:
CustomLog /var/log/apache2/mysite.access.log combined
Then save the file with ctrl-x. Next you need to tell Apache to enable the site. All this seems to do is create a symlink in the sites-enabled directory that points to the file in the sites-available directory. Type the following:
sudo a2ensite mysite.local
There is also a corresponding a2dissite which disables the site by destroying the symlink. Then we need to tell Apache to reload the configuration:
sudo /etc/init.d/apache2 reload
I get a message about not being able to recognize the fully qualified name--that doesn't matter for our purposes here.
This would all work now, except there is nothing telling your computer where to find mysite.local. (This assumes that nothing is already set up in dns somewhere pointing to your site.) Edit the hosts file with
sudo nano /etc/hosts
and add an entry with
then press ctrl-x to save and exit.
http://mysite.localinto your browser and watch the fun begin! You can set up additional parts of the apache configuration by copying the configuration from default to your new file in sites-available, or consulting whatever application you are going to run to see what configuration it requires.