4 simple steps creating virtual host in Ubuntu

Linux, Ubuntu, 2015-06-16 23:52:29 UTC

Usually in standard development process, we use http://localhost/app_name format as URL. The format is not good when compared to the production environment. Usually, production using http://domain_name.com as URL.

To make the development URL format similiar to production URL, we can use virtual host in Ubuntu. Just follow these steps;

1. Open /etc/hosts

$ sudo nano /etc/hosts


in nano editor

127.0.0.1       localhost
127.0.1.1       ubuntu-RV

#add your virtual host name below
127.0.0.5       myproject


# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters



2. Move into apache conf.d folder and  create a configuration file in /etc

$ cd /etc/apache2/confd

$ nano myproject.conf


In Nano editor

<VirtualHost 127.0.0.5>
    DocumentRoot "/home/codescr/sites/myproject/"
    ServerName myproject
    <Directory "/home/codescr/sites/myproject">
        Options Indexes FollowSymLinks MultiViews
        AllowOverride all
    </Directory>
</VirtualHost>


3. Restart Apache service

$ sudo service apache2 restart



4. Then, We can type http://myproject in the browser

http://myproject

 


Share: