Saturday, March 22, 2014

How to setup virtual host in apache2 on ubuntu OS

Virtual host is one of the beautiful option, which is provided by web servers. I have already shared the snacks about XAMPP virtual host creating process. I believe that snacks was tasty and delightful for your coding life.

Here, i am sharing another tasty snacks about Apache2 server virtual host, which is default server of most of linux OS. In order to create virtual host in your linux machine with apache2 server. First you have to place your project folder under root directory (/var/www/).

Create virtual host file in below location with tags

Step 1 : Go to cd /etc/apache2/sites-available/

Step 2 : cp default yoursitename.com

Step 3 : Open your file with following command

sudo gedit  yoursitename.com

Paste the below code into yoursitename.com file.

<VirtualHost *:80>
    ServerAdmin test@test.com

    DocumentRoot /var/www/project-directory/
    ServerName yoursitename.com    

    ServerAlias www.yoursitename.com    
    ErrorLog /var/log/apache2/yoursitename.com-error_log
    CustomLog /var/log/apache2/yoursitename.com-access_log common
</VirtualHost>


Save and close the file.

Step 4 : Enable the site for local server

sudo a2ensite yoursitename.com

Step 5 : Finally add to hosts file.

sudo gedit /etc/hosts

Add below line into hosts file.

127.0.0.1   yoursitename.com

Now you can go to browser and type http://yoursitename.com.

No comments:

Post a Comment