What is Apache2 VirtualHost?
Apache2 VirtualHost is use for multidomain purpose. We need to configure 2 VirtualHost name to each domain, so we can see a different website from each domain.
First I assume we have installed apache2 webserver and it’s running smootly in Ubuntu Server.
To configure apache webserver VirtualHost in Ubuntu server is different from other linux OS like fedora/redhat/centos. In Ubuntu apache2 have separated the virtual host into sites-available and sited-enabled directory.
Example we have domain inferno.web.id
We need to login into the server and have a root user previleges.
We also need to create a file name inferno.web.id in sites-available directory
Password:
root@athena:/home/sentono#
Change directory to /etc/apache2/sites-available/
root@athena:/etc/apache2/sites-available#
Add NameVirtualHost into Default site
root@athena:/etc/apache2/sites-available#pico default
#change or add this line below
NameVirtualHost 192.168.1.1:80
#save and exit
Create a new virtualhost file
<VirtualHost 192.168.1.1:80>
ServerName inferno.web.id
DocumentRoot /home/www/inferno.web.id/public_html/
</VirtualHost>
#save this file and exit
We need to enabled our new Website
root@athena:/etc/apache2/sites-available#a2ensite inferno.web.id
Restart Apache2 Webserver
root@athena:/etc/apache2/sites-available#/etc/init.d/apache2 restart
Create testing index.php
<? phpinfo() ?>
#save and exit
Testing it with IE
http://inferno.web.id