Apache web server is the most common and popular in web arena. It has an awesome feature of customization and running websites using virtualhosts.
In this article we will know how to setup virtualhost on apache on Ubuntu(14.04 currently i am using). We will setup “test.com” which will actually point to “/home/<username>/sites/test.com/index.html”
Before we start we assume you have root access, if necessary. <username> is basically your system user directory.
Step 1: First create a directory where you put all your source code under your home directory(most common place)
[code language=”bash”]
sudo mkdir /home/<username>/sites/test.com
[/code]
Add an index.html(with some content) file under test.com
Step 2: Create a new virtualhost file copying existing file under directory “/etc/apache2/sites-available”
[code language=”bash”]
cd /etc/apache2/sites-available
cp 000-default.conf test.com.conf
[/code]
Set at-least “ServerName” and “DocumentRoot” variable as below
[code language=”bash”]
ย ServerName test.com
ย DocumentRoot /home/<username>/sites/test.com
[/code]
Step 3: Add a host entry into your host file locate under “/etc/hosts”
[code language=”bash”]
sudo vim /etc/hosts
add a line as below
127.0.0.1 test.com
[/code]
Step 4: Now enable VitrualHost using below command and restart apache
[code language=”bash”] sudo a2ensite test.com.conf
sudo apachectl restart
[/code]
Step 5: Open your web browser and hit the url
[code]http://test.com[/code]
In case if you get message like “You don’t have permission to access / on this server. “, Please ensure that “test.com” directory permission is set to 0777. Grant the required permission if necessary.
Reblogged this on SutoCom Solutions.
@SUTOCOM Thanks for Liking and sharing ๐