How to Set Up Virtual Host in Ubuntu 14.04

Wednesday, October 22, 2014 govindkewat.com 30 Comments


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.


30 comments:

  1. Hi, thanks for post! But why did you set example.com to 127.0.0.2 not to 127.0.0.1?

    ReplyDelete
    Replies
    1. Oh! My mistake it's 127.0.0.1. You can set many host on single IP Address. :)

      Delete
  2. From your discussion I have understood that which will be better for me and which is easy to use. Really, I have liked your brilliant discussion. I will comThis is great helping material for every one visitor. You have done a great responsible person. i want to say thanks owner of this blog.
    online Python training | python training in chennai

    ReplyDelete
  3. I prefer to study this kind of material. Nicely written information in this post, the quality of content is fine and the conclusion is lovely. Things are very open and intensely clear explanation of issues
    angularjs Training in bangalore

    angularjs Training in bangalore

    angularjs online Training

    angularjs Training in marathahalli

    angularjs interview questions and answers

    ReplyDelete
  4. Probably, of all the preferences, this casino is my favorite . superb bonus slot machines I like everything in the casino, the roulette is excellent, I am glad that during the game you can also talk to people who also play at the same table! Muzychka great. With the conclusion there were no difficulties at all. Easily raised from $ 30 to $ 600, withdraw. Played, played, will play

    ReplyDelete
  5. I am happy for sharing on this blog its awesome blog I really impressed. thanks for sharing.

    Become an Expert In SAP BASIS Training! The most trusted and trending Programming Language. Learn from experienced Trainers and get the knowledge to crack a coding interview, @Softgen Infotech Located in BTM Layout.

    ReplyDelete
  6. If you don"t mind proceed with this extraordinary work and I anticipate a greater amount of your magnificent blog entries dich vu tong dai ao

    ReplyDelete
  7. I really enjoy reading and also appreciate your work. USA RDP

    ReplyDelete
  8. amazing information...I’m using the same blog platform like yours, and I’m having difficulty finding one? Thanks a lot.

    BEST ANGULAR JS TRAINING IN CHENNAI WITH PLACEMENT

    https://www.acte.in/angular-js-training-in-chennai
    https://www.acte.in/angular-js-training-in-annanagar
    https://www.acte.in/angular-js-training-in-omr
    https://www.acte.in/angular-js-training-in-porur
    https://www.acte.in/angular-js-training-in-tambaram
    https://www.acte.in/angular-js-training-in-velachery

    ReplyDelete
  9. Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep sharing this blogging…

    android training in chennai

    android online training in chennai

    android training in bangalore

    android training in hyderabad

    android Training in coimbatore

    android training

    android online training

    ReplyDelete
  10. If you use our products,you will definitely benefit from our products,which will be very beneficial for
    your health.Toincrease your weight,give us a chance to serve once.If you use Parivartan Ayurveda products,we assure you that you will definitely gain 100% weight and complete Ayurvedic product.

    More Info :- https://www.parivartanayurveda.com/how-to-weight-gain.php
    https://www.parivartanayurveda.com/
    https://www.parivartanayurveda.com/weight_gain.php

    ReplyDelete
  11. Day To Day Update Provide You Latest Health Updates,Your Life Style,Healthy Living,Entertainment News: Bollywood , World News, National News ,TV News, Politics News and Celebrity Gossip Today ..

    More Info :- https://daytodayupdate.com/

    ReplyDelete
  12. This is a smart blog. I mean it. You have so much knowledge about this issue, and so much passion. You also know how to make people rally behind it, obviously from the responses. whrmarketing

    ReplyDelete
  13. Awesome article, it was exceptionally helpful! I simply began in this and I'm becoming more acquainted with it better! Cheers, keep doing awesome! nehézgépszállítás Europa-Road Kft.

    ReplyDelete
  14. Website admins need to know the ideal opportunity they need to begin turning away from their common host and overhaul their site to VPS facilitating. https://onohosting.com/

    ReplyDelete
  15. Best Forex VPS that designate high configuration, low latency, Scalable and Dedicated Forex Trading Virtual Private Server. To operate multiple MT4 or many other trading applications, there's no alternative to exclusive dedicated Forex VPS other than Flexi Fx Servers.
    Best forex vps

    ReplyDelete
  16. buy youtube views if you have never worked in the video game industry, landing your first video game tester job can seem a bit intimidating. Don't fret - we all have to start somewhere, and if you are determined to start a video game tester career, there is a simple, yet highly successful process that anyone can use to make it happen.

    ReplyDelete
  17. Software, such as the ThinPoint, doesn't take that much resources to run since it doesn't create virtual machine for every user. best teamviewer alternatives

    ReplyDelete
  18. As responsibilities and the demands of adult life increase, the concept of play is often relegated to the background https://petrogalant.com/

    ReplyDelete