Setting Up Virtual Host - Linux

by Devansh

Posted on 30 Mar 2018 10:03:27 (2 years ago)

In this section I will only share a commands to setup a virtual host in linux. These commands I have used in Ubuntu 16.04 LTS with APACHE2 Server. Hope these commands will also work on all Linux OS as well. So keeping the post short and sweet below are the commands. Test it with your new project and have fun.

1. cd /var/www

2. Create your project directory here
   => sudo mkdir -p

3. cd /var/www/
   => Paste all your codes in this directory

4. cd /etc/apache2/sites-available/

5. Copy Default Configuration for your project
   => sudo cp 000-default.conf

6. sudo nano
   => Paste the below codes in conf file
	  DocumentRoot /var/www/
	  ErrorLog ${APACHE_LOG_DIR}/error.log
	  CustomLog ${APACHE_LOG_DIR}/access.log combined

7. Enable your site conf
   => sudo a2ensite

8. Disable your default conf
   => sudo a2dissite 000-default.conf

9. Restart your apache server
   => sudo service apache2 restart

10. /etc/hosts
   => Assign your IP for domain