Showing posts with label Virtual Host. Show all posts

How to Set Up Virtual Host in Ubuntu 14.04


Today I came up with new topic that is How to Set Up Virtual Host in Ubuntu.

About Virtual Host

Virtual host is used to set many hosts on the same IP address. Their is no limit on the number to hosts to be added in Virtual Host. Using this we can display different information to user depends on different Host.

I am taking 'example.com' as Virtual Host name. You can customize it.
You need Apache should be installed on system. Here is the guide to install Apache in Ubuntu.

Steps To Set Up Virtual Host 

1. Open Terminal (Shortcut ctrl+alt+t).
2. Create directory  ' sudo mkdir /var/www/example.com '.
3. Create index.html file ' sudo nano /var/www/example.com/index.html '.
4. Paste below code into index.html

<html>
  <head>
    <title>www.example.com</title>
  </head>
  <body>
    <h1>Congrats! You Have Set Up a Virtual Host Successfully.</h1>
  </body>
</html>

5. Now copy the default configuration file.
       sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/example.com.conf 

6. Now edit this duplicate file 'example.com.conf'
    sudo nano /etc/apache2/sites-availble/example.com.conf   

7. Set ServerName, ServerAlias, DocumentRoot
             ServerName example.com
             ServerAlias www.example.com
             DocumentRoot /var/www/example.com
    Make the changes and save the file.

8. Now enable the new configuration file i.e. example.com
               sudo a2ensite example.com

9. Restart Apache
              sudo service apache2 restart

10. Now set Up the local host file
             sudo nano /etc/hosts

11. Add virtual host
             # Host DatabaseNow DIY. Like & share
             #
             # localhost is used to configure the loopback interface
            # when the system is booting.  Do not change this entry.
            ##
            127.0.0.1       localhost
            127.0.0.2       example.com
            127.0.0.1       example.com
     Add host and save the file.

12. Now its done you can check using browser.
Add comment below if you got stuck in any step. We will sort out. Have a good day. Please like and share to appreciate my work.