Problem:
Host multiple low traffic websites on one Linux machine with one IP address is an low cost option for web hosting industry. It is very easy to do with Ubuntu 10.04, name Lucid, which is free from Ubuntu.com.
Steps:
After you install Ubuntu 10.04 LAMP server on your computer, following these steps to setup name based virtual hosts. I use www.sample1.com and www.sample2.org for illustration below
- Create file sample1.com under “/etc/apache2/sites-available” with following lines
<VirtualHost *:80>
ServerAdmin webmaster@sample1.com
ServerName www.sample1.com
ServerAlias sample1.com
DocumentRoot /var/www/sample1.com/public_html/
ErrorLog /var/www/sample1.com/logs/error.log
CustomLog /var/www/sample1.com/access.log combined
</VirtualHost> - Create file sample2.org under “/etc/apache2/sites-available” with following lines
<VirtualHost *:80>
ServerAdmin webmaster@sample1.com
ServerName www.sample2.org
ServerAlias sample2.org
DocumentRoot /var/www/sample2.org/public_html/
ErrorLog /var/www/sample2.org/logs/error.log
CustomLog /var/www/sample2.org/access.log combined
</VirtualHost> - Create necessary directories sample1.com and sample2.org under /var/www/ and their sub-directories public_html and logs
- Enable both sites with
a2ensite sample1.com
a2ensite sample2.org - Reload appach2 with /etc/init.d/apache2 reload
- If you put different index.html under /public_html of each website, you should see if when you visit the site.
Note:
To remove a site from Apache, use command: a2dissite sample1.com
Reference: