Hi all, from this post I’m going to show you how to configure the virtual host in Apache HTTP server. When we have created a virtual host in our Apache server, then we can access different projects as the server. Normally we are accessing the apache server hosts using the ‘localhost‘ or by using the IP address, ‘127.0.0.1‘. But when we have configured virtual hosts, then we can access by giving a url as well. Let’s see how to do the configuration step by step.
- First of all you have to open the ‘httpd.conf‘ file from your apache server installation location. The default path is ‘/usr/local/apache2/conf/httpd.conf‘.
- At the end of the file, there is a line like below which has been commented. We should to remove the comment.
- Then save and exit the file.
- Next you can create a folder and your web page at desired location.
- Should change the directory and file permissions to be executed as well.
chmod a+x firstVirtualHost
chmod a+x index.html
- Next we need open the ‘httpd-vhosts.conf‘ file which is located at ‘/usr/local/apache2/conf/extra/‘ by default.
- Then you should edit the document like below.
Document root = Where the virtual host file is located. The directory you created.
Server name = anything you like
Server alias = anything you like. This is the domain what we are going to use to access the virtual host.
<Directory></Directory> : Same as the document root, but this is very important.
- Just one more thing to do. Access the ‘users‘ file which is located at ‘/etc/‘ and change like below with your Server alias and IP address.
- Now you are ready to go. Open your browser and type the ‘localhost‘, this will show your normal index file. Then type your server alias which you ave earlier. It’s working too.
Hope now you have a clear idea about what the virtual host means and how to configure virtual host in Apache HTTP server. Thank You!