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.
Effective Use of Resources: By hosting multiple websites on one server, you can make better use of the server’s resources. Rather than each website having its own dedicated server, multiple websites can share the same resources, like CPU, RAM, and Storage.
Affordable: Shared hosting is mainly more cost-effective than hosting each website on its own server. This is because you are sharing the cost of the server and its resources with other users, making it more affordable for individual website owners.
Centralized Management: With shared hosting, you can handle all your websites from an individual control panel. It makes it easier to monitor and handle your websites, as you do not have to log in to several accounts or servers.
Scalability: Shared hosting plans generally deliver scalability, enabling you to easily upgrade your hosting plan as your website grows. This can be more affordable than upgrading to a dedicated server, mainly for small businesses or individuals.
Smooth Setup: Setting up several websites on one server is generally simple & straightforward, mainly if you are using a hosting provider that delivers shared hosting plans. You can instantly integrate new websites into your account and configure them.
Security: While security can be an issue with shared hosting due to the server's shared nature, reputable hosting providers take measures to ensure server security. Moreover, you can implement security measures on your websites to protect them from threats.
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.
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
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
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
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
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>
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
Before restarting Apache, verify there are no configuration errors.
sudo apache2ctl configtest
Expected output:
Syntax OK
Apply the new configuration.
sudo systemctl restart apache2
Verify Apache is active.
sudo systemctl status apache2
Log in to your domain registrar or DNS provider.
If you're using UFW, allow Apache traffic.
sudo ufw allow 'Apache Full'
Check the firewall status.
sudo ufw status
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.