Virtual host - ubuntu(linux)

Create(set) virtual host as local domain- ubuntu(linux)


Sometimes we need to create a local domain for the sites in our local server. To accomplish this purpose, we need to create a virtual host entry in apache hosts and respectively create its dependencies as well. Example : localhost/myproject => myproject.localhost

To meet the above described requirements, we need to follow below steps over your terminal(command-line) considering you are at /(root) directory:

1- Create your site's conf file under the directory : etc/apache2/sites-enabled.

Enter command :

- sudo cp /etc/apache2/sites-enabled/default.conf /etc/apache2/sites-available/myproject.localhost.conf

- sudo nano /etc/apache2/sites-enabled/myproject.localhost.conf

Make the changes as defined below:

<VirtualHost *:80>
        ServerAdmin webmaster@localhost
        ServerName myproject.localhost

        DocumentRoot /var/www/myproject

        <Directory /var/www/myproject>
                Options Indexes FollowSymLinks
                AllowOverride All
                Require all granted
        </Directory>
        ErrorLog /var/log/apache2/cphd-error.log
        CustomLog /var/log/apache2/cphd-access.log common
</VirtualHost>

2- Make your host entry for "myproject.localhost" against host IP : 127.0.1.1  .

-sudo nano /etc/hosts ( for new host entry )
127.0.1.1 myproject.localhost

3- sudo service apache2 restart( start/stop apache service )

Now you will be able to access your project/site via direct host link( myproject.localhost ) rather than accessing via directory path( localhost/myproject ).

[ Note: default.conf file name can be different. You may see under the specified directory. ]


Thanks for your valuable comments and suggestions

Comments

Popular posts from this blog

MWS (Amazon Marketplace Web Service) API Integration

CURL Basics with Example

YouTube TV | Know All About Features, Subscription & Access