cPanel & WHM Tutorials

How to Run Multiple Sites on One Server Using Virtual Hosts

How to Run Multiple Sites on One Server Using Virtual Hosts

If you’re running more than one website, you don’t necessarily need separate servers for each. With Virtual Hosts, you can host multiple websites, each with its own domain name, content, and configuration, on the same physical or virtual server. This is not only cost-effective but also much easier to manage, especially if you’re using a powerful hosting service like Vicservers.

In this guide, we’ll walk you step-by-step through setting up multiple sites on one server using Apache’s Virtual Host feature.

What Are Virtual Hosts?

Virtual Hosts allow a single web server to serve different websites based on:

  • Domain Name (Name-based hosting)
  • IP Address (IP-based hosting)
  • Port Number (Port-based hosting)

Most commonly, name-based virtual hosting is used — meaning that Apache identifies which site to serve by checking the Host header in the request.

For example:

  • www.site1.com/var/www/site1
  • www.site2.com/var/www/site2

Both can be hosted on the same server and IP.

Prerequisites

Before you begin, ensure you have:

  • A Linux server (Ubuntu 20.04/22.04 recommended)
  • Apache installed
  • Root or sudo access
  • Two (or more) domain names pointed to your server’s IP address
  • Basic command-line knowledge

If you don’t have a VPS yet, Vicservers offers affordable, high-performance VPS solutions perfect for hosting multiple sites.

Step 1: Install Apache

If you don’t already have Apache installed:

sudo apt update
sudo apt install apache2 -y

Enable Apache to start on boot:

sudo systemctl enable apache2
sudo systemctl start apache2

Step 2: Create Directory Structure for Each Website

You’ll need a separate root directory for each site.

sudo mkdir -p /var/www/site1.com/public_html
sudo mkdir -p /var/www/site2.com/public_html

Set permissions:

sudo chown -R $USER:$USER /var/www/site1.com/public_html
sudo chown -R $USER:$USER /var/www/site2.com/public_html

Step 3: Add Sample Content

For site1.com:

echo "<h1>Welcome to Site 1</h1>" > /var/www/site1.com/public_html/index.html

For site2.com:

echo "<h1>Welcome to Site 2</h1>" > /var/www/site2.com/public_html/index.html

Step 4: Create Virtual Host Files

Apache stores Virtual Host configs in /etc/apache2/sites-available/.

For site1.com:

sudo nano /etc/apache2/sites-available/site1.com.conf

Add:

<VirtualHost *:80>
    ServerAdmin admin@site1.com
    ServerName site1.com
    ServerAlias www.site1.com
    DocumentRoot /var/www/site1.com/public_html
    ErrorLog ${APACHE_LOG_DIR}/site1_error.log
    CustomLog ${APACHE_LOG_DIR}/site1_access.log combined
</VirtualHost>

For site2.com:

sudo nano /etc/apache2/sites-available/site2.com.conf

Add:

<VirtualHost *:80>
    ServerAdmin admin@site2.com
    ServerName site2.com
    ServerAlias www.site2.com
    DocumentRoot /var/www/site2.com/public_html
    ErrorLog ${APACHE_LOG_DIR}/site2_error.log
    CustomLog ${APACHE_LOG_DIR}/site2_access.log combined
</VirtualHost>

Step 5: Enable the New Sites

Enable each Virtual Host:

sudo a2ensite site1.com.conf
sudo a2ensite site2.com.conf

Disable the default Apache site (optional):

sudo a2dissite 000-default.conf

Reload Apache:

sudo systemctl reload apache2

Step 6: Update DNS Records

In your domain registrar’s panel:

  • Create an A Record for site1.com → your server’s IP
  • Create an A Record for site2.com → your server’s IP
  • Optionally add www CNAME records pointing to the root domains

Step 7: Add SSL Certificates

Using Let’s Encrypt for free SSL:

Install Certbot:

sudo apt install certbot python3-certbot-apache -y

Run:

sudo certbot --apache -d site1.com -d www.site1.com
sudo certbot --apache -d site2.com -d www.site2.com

This will configure HTTPS automatically.

Step 8: Test the Setup

Open:

http://site1.com
http://site2.com

You should see different pages for each site.

Best Practices for Running Multiple Sites on One Server

  1. Use Strong Permissions
    • Don’t run sites as root
    • Use separate system users if possible
  2. Enable Resource Limits
    • Use Apache’s mod_evasive and mod_security to prevent abuse
  3. Monitor Server Load
    • Tools like htop, top, or VicServers’ built-in monitoring help track CPU/memory usage
  4. Keep Backups
    • Automate backups with rsync or VicServers’ backup solutions
  5. Keep Software Updated
    • Regularly update Apache, PHP, and system packages

Why Use Vicservers for Multiple Site Hosting?

Running multiple sites requires:

  • High uptime (Vicservers guarantees 99.9%)
  • Scalable resources
  • Expert support
  • Easy DNS management
  • Security-first infrastructure

With Vicservers’ VPS and dedicated plans, you get:

  • Full root access for complete control
  • SSD storage for fast load times
  • Free SSL certificates
  • 24/7 Nigerian-based support

Conclusion

Virtual Hosts make it easy to host multiple websites on one server without sacrificing performance or security. With Vicservers providing reliable hosting infrastructure, you can scale your web projects without breaking the bank.

Need help setting this up?
Vicservers offers FREE Virtual Host setup for new VPS customers.

Get Started with Vicservers Today

 

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button