How to Create Virtual host in ubuntu ?

sudo nano /etc/apache2/sites-available/local.testing.com

You can choose any file name instead of  “local.testing.com”. 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]
        </IfModule>
    </Directory>

    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
</VirtualHost>

Now open hosts file in editing mode :

sudo nano /etc/hosts

add Ip 127.0.0.1 and the file. In this file you register your file created in sites-available

127.0.0.1 localhost
#newly added
127.0.0.1 http://www.testing.com

# 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 http://www.testing.com

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 http://www.testing.com or enter the IP address 12.7.0.0.1 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 http://www.testing.com file inside sites-available folder.

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s