Setting up virtual hosts on Linux
Today we will be setting a virtual host on Ubuntu. Virtual host is the practice of hosting more than one server on a single machine. In our case our server will not be live on the Internet, but we do want to have the ability to create local domain names such as:
http://my.domain/
http://test.site/
http://mottis.site/
http://example/
or anything else you have in your mind that could make your organization easier.
In this tutorial I will be using Ubuntu 11, with Apache 2.2.17
The first thing that you would want to do is to open Terminal, and navigate to the apache2 sites folder
cd /etc/apache2/sites-available
next, we will create a new config file, with the following code:
sudo gedit test.site.conf
and insert the following lines of code in it
<VirtualHost test.site> ServerAdmin webmaster@localhost ServerAlias test.site DocumentRoot /home/motti/sites/test.site #we want specific log file for this server CustomLog /var/log/apache2/test.site-access.log combined </VirtualHost>
The next step would be to add test.site to our local hosts file, ensuring it will look for this domain locally, to do that, edit the hosts file and add test.site to it.
sudo gedit /etc/hosts
127.0.0.1 localhost test.site
Now we want to enable to site, we do that by typing the following line.
sudo a2ensite test.site.conf
All we have left to do now is to reload the server, and we should be all set.
sudo /etc/init.d/apache2 reload

0 Comments