Net2Secure: A Leading Data Center Service Provider in India

Home Knowledge Base Tech Guide /

A Guide to Hosting Several Websites on a Single Server


Managing several websites doesn’t often require purchasing a separate server for each one. Whether you are a web developer handling client projects, a digital agency hosting several business websites, or a firm operating multiple domains, hosting several websites on a single server is an affordable and effective solution. 

Modern web hosting technologies make it possible to serve various websites from one VPS, dedicated server hosting, or cloud server hosting while maintaining performance, security, and flexibility. By configuring your web server accurately and organizing your hosting environment, you can handle multiple domains with ease without compromising reliability. 

In this post, you will learn how to host several websites on a single server, different hosting methods, configuration best practices, and crucial considerations to ensure each website operates effortlessly and securely.

Key Benefits of Hosting Multiple Websites on One Server

Steps to Host Multiple Websites on One Server <> Apache

Hosting multiple websites on a single Apache server is done through Virtual Hosts. A Virtual Host tells Apache which website to serve based on the domain name requested by the visitor. Each website can have its own document root, configuration, logs, and SSL certificate while sharing the same server.

This guide assumes you're using Ubuntu or Debian with Apache installed and have root or sudo access to your server.

Step 1: Install Apache

If Apache is not already installed, update your package list and install the Apache web server.

sudo apt update
sudo apt install apache2 -y

Verify that Apache is running:

sudo systemctl status apache2

If it isn't running, start and enable it:

sudo systemctl start apache2
sudo systemctl enable apache2

Step 2: Create Separate Website Directories

Each website should have its own document root.

Example:

/var/www/
├── website1.com/
│   └── public_html
└── website2.com/
    └── public_html

Create the directories:

sudo mkdir -p /var/www/website1.com/public_html
sudo mkdir -p /var/www/website2.com/public_html

Step 3: Set Directory Permissions

Assign ownership to your user account.

sudo chown -R $USER:$USER /var/www/website1.com
sudo chown -R $USER:$USER /var/www/website2.com

Grant proper permissions.

sudo chmod -R 755 /var/www

Step 4: Create Sample Web Pages

Create an index page for each website.

Website 1:

nano /var/www/website1.com/public_html/index.html

Example content:

<h1>Welcome to Website 1</h1>

Website 2:

nano /var/www/website2.com/public_html/index.html

Step 5: Create Virtual Host Configuration Files

Apache stores Virtual Host configurations inside:

/etc/apache2/sites-available/

Create the first configuration:

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

Add:

<VirtualHost *:80>
    ServerName website1.com
    ServerAlias www.website1.com

DocumentRoot /var/www/website1.com/public_html

ErrorLog ${APACHE_LOG_DIR}/website1-error.log
    CustomLog ${APACHE_LOG_DIR}/website1-access.log combined
</VirtualHost>

Create another configuration for the second website:

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

<VirtualHost *:80>
    ServerName website2.com
    ServerAlias www.website2.com

DocumentRoot /var/www/website2.com/public_html


    ErrorLog ${APACHE_LOG_DIR}/website2-error.log
    CustomLog ${APACHE_LOG_DIR}/website2-access.log combined
</VirtualHost>

Step 6: Enable the Virtual Hosts

Enable each website configuration.

sudo a2ensite website1.com.conf

sudo a2ensite website2.com.conf

Disable the default Apache site if it's no longer needed.

sudo a2dissite 000-default.conf

Step 7: Test the Apache Configuration

Before restarting Apache, verify there are no configuration errors.

sudo apache2ctl configtest

Expected output:

Syntax OK

Step 8: Restart Apache

Apply the new configuration.

sudo systemctl restart apache2

Verify Apache is active.

sudo systemctl status apache2

Step 9: Configure DNS Records

Log in to your domain registrar or DNS provider.

Step 10: Allow HTTP and HTTPS Through the Firewall

If you're using UFW, allow Apache traffic.

sudo ufw allow 'Apache Full'

Check the firewall status.

sudo ufw status

Step 11: Verify Your Websites

Open a web browser and visit:

http://website1.com

and

http://website2.com

If SSL has been configured, verify:

https://website1.com

https://website2.com

Thus, Apache Virtual Hosts deliver a reliable and scalable way to host several websites on a single server. By assigning each domain its own document root and virtual host configuration, you can effectively handle various websites while decreasing infrastructure costs. With proper DNS configuration, SSL certificates, and regular maintenance, your server can safely host multiple websites from an individual hosting environment. 


Abhay Pratap Singh

By Abhay Pratap Singh

Abhay Singh is a digital marketing strategist, technology writer, and SEO specialist with a passion for helping businesses grow through data-driven digital solutions. He specializes in search engine optimization (SEO), web hosting technologies, cybersecurity trends, cloud computing, website performance optimization, and emerging digital innovations.

With years of experience in content strategy and technical SEO, Abhay has authored numerous in-depth guides, tutorials, and industry insights that help businesses, website owners, and IT professionals navigate the evolving digital landscape. His expertise spans website optimization, DNS management, web hosting infrastructure, cybersecurity best practices, and AI-driven digital marketing strategies.

View all of Abhay Pratap Singh's posts.

Contact Us


Related Tech Guide Posts

We use cookies

By continuing to browse this site, you are agreeing to the use of cookies to enhance your experience.