How to Create Virtual host in ubuntu ?

sudo nano /etc/apache2/sites-available/

You can choose any file name instead of  “”. Now enter your password. An empty file would be created. Paste this test :

<VirtualHost *:80>
    ServerName www.bow.loc
    ServerAlias bow.loc
    DocumentRoot /var/www/html/bow/web

    <Directory /var/www/html/bow>
        AllowOverride All
        Options FollowSymLinks MultiViews
        Order allow,deny
        Allow from all
        <IfModule mod_rewrite.c>
            RewriteEngine On
            RewriteCond %{REQUEST_FILENAME} !-f
            RewriteRule ^(.*)$ /app.php [QSA,L]

    ErrorLog ${APACHE_LOG_DIR}/error.log
    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn
    CustomLog ${APACHE_LOG_DIR}/access.log combined

Now open hosts file in editing mode :

sudo nano /etc/hosts

add Ip and the file. In this file you register your file created in sites-available localhost
#newly added

# 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

Now enable the site that you have registered :

sudo e2ensite

restart the apache2 :

 sudo /etc/init.d/apache2 restart

From terminal side it is done. Also working if you are not using any proxy network.

If you are using the proxy then come on browser and set the no proxy for or enter the IP address here. Now before checking on external server first browser will attempt to find out whether this site exists internally or not. If exists (in this case) will be loaded from the path provided in file inside sites-available folder.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.