I think most of the people used ubuntu as their linux OS. There will be a little bit conflict when you are trying to use virtual hosting in apache2 according to centOS. In this article I will try to explain how it should done in ubuntu apache2.
Anyway there is a few more things to know before you start.
1. httpd.conf file is equal to apache2.conf in /etc/apache2/
2. In apache2.conf includes some other conf file so that necessary settings should be done those files. e.g. changing port numbers should be done in ports.conf
I will explain step by step vertual hosting using apacge2.
I take /etc/var/www as a DocumentRoot any way if you want to change it,
Change the default file which locate in /etc/apache2/sites-available/default file.
To easy access create a folder called www.bict.lk (any choice) and create htdocs and logs two folders inside www.bict.lk. Don't forget to create index.html file in htdocs folder. (html file which shows www.bict.lk ). These folders should be create according to your DocumentRoot.
In my case whole path is : /etc/var/www/www.bict.lk/htdocs/ to the index.html of bict.lk
Now go inside to the /etc/apache2/sites-available folder and create a txt file www.bict.lk and it should be looks like this :
note : creating new files may be not allowed, in that case you should run as root and use touch command to create and vi to edit it.
#
# Example.com (/etc/apache2/sites-available/www.bict.lk)
#
<VirtualHost 192.168.1.1:8080>
ServerAdmin webmaster@localhost
ServerName www.mypage.com
ServerAlias bict.lk
# Indexes + Directory Root.
DirectoryIndex index.html
DocumentRoot /var/opt/www.bict.lk/htdocs/
# CGI Directory
ScriptAlias /cgi-bin/ /var/opt/www.bict.lk/cgi-bin/
<Location /cgi-bin>
Options +ExecCGI
</Location>
# Logfiles
ErrorLog /var/opt/www.bict.lk/logs/error.log
CustomLog /var/opt/www.bict.lk/logs/access.log combined
</VirtualHost>
In blue color I will show where the places you should change. In log files the names (error.log and access.log ) keep without change. It is not must, but it is better. IP and the port is key and it should be match to your settings.
There is a another folder called sites-enable in apache2. When we create new sites it should be in sites-available but when apache run it look in the sites-enable.So we had to match those using SymLink. To do that use this command.
$ a2ensite www.bict.lk
When you done that you can see automatically new file will be created in sites-enabled folder as www.bict.lk
Ok. now you had to change your IP address;
$ifconfig eth0:0 192.168.1.1
port should be change in /etc/apache2/port.conf as Listen *:8080
now restart your server;
/etc/init.d/apache2 restart
and type 192.168.1.1:8080 in your browser. If it is ok then you should see index of www.bict.lk.
If you want to access this using url, then you should update /etc/hosts file as
192.168.1.1 www.bict.lk
Then type www.bict.lk:8080 in your browser and see.
That ' s all.....!
Anyway there is a few more things to know before you start.
1. httpd.conf file is equal to apache2.conf in /etc/apache2/
2. In apache2.conf includes some other conf file so that necessary settings should be done those files. e.g. changing port numbers should be done in ports.conf
I will explain step by step vertual hosting using apacge2.
I take /etc/var/www as a DocumentRoot any way if you want to change it,
Change the default file which locate in /etc/apache2/sites-available/default file.
To easy access create a folder called www.bict.lk (any choice) and create htdocs and logs two folders inside www.bict.lk. Don't forget to create index.html file in htdocs folder. (html file which shows www.bict.lk ). These folders should be create according to your DocumentRoot.
In my case whole path is : /etc/var/www/www.bict.lk/htdocs/ to the index.html of bict.lk
Now go inside to the /etc/apache2/sites-available folder and create a txt file www.bict.lk and it should be looks like this :
note : creating new files may be not allowed, in that case you should run as root and use touch command to create and vi to edit it.
#
# Example.com (/etc/apache2/sites-available/www.bict.lk)
#
<VirtualHost 192.168.1.1:8080>
ServerAdmin webmaster@localhost
ServerName www.mypage.com
ServerAlias bict.lk
# Indexes + Directory Root.
DirectoryIndex index.html
DocumentRoot /var/opt/www.bict.lk/htdocs/
# CGI Directory
ScriptAlias /cgi-bin/ /var/opt/www.bict.lk/cgi-bin/
<Location /cgi-bin>
Options +ExecCGI
</Location>
# Logfiles
ErrorLog /var/opt/www.bict.lk/logs/error.log
CustomLog /var/opt/www.bict.lk/logs/access.log combined
</VirtualHost>
In blue color I will show where the places you should change. In log files the names (error.log and access.log ) keep without change. It is not must, but it is better. IP and the port is key and it should be match to your settings.
There is a another folder called sites-enable in apache2. When we create new sites it should be in sites-available but when apache run it look in the sites-enable.So we had to match those using SymLink. To do that use this command.
$ a2ensite www.bict.lk
When you done that you can see automatically new file will be created in sites-enabled folder as www.bict.lk
Ok. now you had to change your IP address;
$ifconfig eth0:0 192.168.1.1
port should be change in /etc/apache2/port.conf as Listen *:8080
now restart your server;
/etc/init.d/apache2 restart
and type 192.168.1.1:8080 in your browser. If it is ok then you should see index of www.bict.lk.
If you want to access this using url, then you should update /etc/hosts file as
192.168.1.1 www.bict.lk
Then type www.bict.lk:8080 in your browser and see.
That ' s all.....!
Nice work man, keep it up. :)
ReplyDelete$sudo a2dissite
ReplyDeleteThis Will remove the symlinks from sites-enabled so that the site configured in sitefilename will not be served,
We need to create symlink between these two folders for each virtual host or you can use a2ensite for this,
$sudo a2ensite
This Will create the correct symlinks in sites-enabled to allow the site configured in sitefilename to be served.
what about this..
$ln -s /etc/apache2/sites-available/bict.lk /etc/apache2/sites-enabled/bict.lk
absolutly correct machan, I make some mistake, to create symLink should use a2ensite,
DeleteAnd I correct it. thanks for your comment
Delete