Creating virtual host in Apache server on Ubuntu

It’s always a good practice to create a virtual host whenever you are starting a new project. It will help you to create approximately same environment as on production. So it will be easy for you to deploy your project on production.

There are some simple steps to create a virtual host.

Step 1:

Create a new directory which will contain all project files. This directory’s path will be set as a root directory for the virtual host.  Generally we create this directory in /var/www/ , but you are free to create anywhere. Also create a index.html with some text.

Open Terminal (Alt+Ctrl+T) and run these commands..

write Hello world! In this file and save it.

I just created practise.com directory in /var/www/ , this directory is going to be default directory.

Step 2:

Create conf file for a virtual host with apache configurations…

Run these commands

Now paste this code in the file and save it.

 

This is the basic configuration where you need to define DocumentRoot path which is the path for the directory containing your project files.

ServerName is the name of domain(virtual host).

 

You may also define some other options within VirtualHost tag like

ServerAlias server

ServerAdmin admin@tekina.info

ErrorLog logs/practise.com-error_log

CustomLog logs/practise.com-access_log

 

Now restart apache server

Step 3:

Now you need to add a host in your /etc/hosts file. By default you may have

Just run command

Now add this line into the hosts file at the end of file

Save this file

 

Open http://practise.com/ in your browser, you should see Hello world!.

Learn how to use mongoDB in CodeIgniter.

Please follow and like us:
20