How to setup virtual web hosting and host multiple sites on single server? [ In two minute ]

Dheeraj jha
2 min readDec 20, 2019

Learn how to set up virtual web hosting for multiple domains to be served from one single server.

Photo by Taylor Vick on Unsplash

But if you are having a pretty robust server and/or you planning to deploy multiple websites on single server under multiple domains, you need to step ahead and create virtual hosts in apache2 settings, which i’ll explain how you can proceed and get your new site up and running on same server in few minutes.

This procedure i am explaining is for ubuntu with apache2 so everything going to be accordingly.

:/var/www/html/

: /etc/apache2/

Site configurations :/etc/apache2/sites-available/

Setting up sites in directory

First of all you need to make sure your website/web app resides somewhere in web root directory, suppose you’ve directory called sites

And you have 2 sites in it with folder site1.com and site2.com

Pointing your domain to server

You can simply put IP address of server in your DNS setting which will start pointing your domain to server where you are about to host your websites/web app.

It might take 30 minute to 1 hour to complete this process, you can check this as follow

This will show your server’s IP address once it’s updated.

Now let’s proceed to virtual host creation.

Create virtual host configuration

● Your email address for webmaster

● Document root for your website folder

● Error log name to identify error of your site

● Access log file name to identify log for your site

You are almost done.

Enable site configuration

Now you need to enable this configuration to enable site on your machine.

For this you need to execute simple a2ensite command for your newly configured site.

And yes you have enabled this site in your configuration, you are one command away to make your site1.com live, just restart your apache and done.

Once the command is executed successfully, your site site1.com can be accessed from web directly and you can see web pages/apps stores in /var/www/html/sites/site1.com/ directory

What’s next?

If you face any problem in saving or execution of apache, check everything once again, for any typo or similar stuff.

Also do not forget to check apache error log if any, and if you are not able to restart apache.

If you find it useful, please share it to your peers on social media and follow @inteligentcomp on twitter/facebook for more updates.

Originally published at https://www.inteligentcomp.com.

--

--

Dheeraj jha

DevOps Engineer | Team lead | AWS | Docker | CI/CD | Gitlab-CI