Host multiple websites on Ubuntu – Apache version

New guide on how to how host multiple websites on Ubuntu server, with Apache. In this guide we’ll cover how to install two websites but you can do more, the concept is the same.

Installing Apache

The first thing you want to do is updating the system.

sudo apt update

Now install the Apache server

sudo apt install apache2

Opening the ports

Now that you have installed the server you have to open the ports so:

sudo ufw allow 80

Move the websites or create new

First thing is to create a directory where you’ll put the websites:

sudo mkdir /websites

Now in here we recommend creating the websites directory name with the domain in it for example:

cd /websites
sudo mkdir /

Now using FTP or SFTP move the websites from your pc to the vps or simply create your websites from the vps. (we won’t cover how to do basic html code)

Giving permissions

Now you have to make sure that the server has access to the files, so run:

sudo chown -R www-data:www-data /websites

Virtual host File

Last thing is to create the virtual host file, which is one important thing to host multiple websites on ubuntu. Navigate to:

cd /etc/apache2/sites-available/

Here you can make one single file for all the websites or make n files for n websites, however we recommend creating separate files.

sudo nano
<VirtualHost *:80>
    DocumentRoot /websites/

    <Directory />
        Options FollowSymLinks
        AllowOverride All-
        Require all granted

    ErrorLog ${APACHE_LOG_DIR}/
    CustomLog ${APACHE_LOG_DIR}/ combined
    RewriteEngine on
    RewriteCond %{SERVER_NAME} [OR] RewriteCond %{SERVER_NAME}


Name the file as you like we still recommend naming them with the domain name.

Now you have to enable those configuration files:

sudo a2ensite

Now remove the basic configuration:

sudo a2dissite 000-default.conf

Enable the URL Rewrite

sudo a2enmod rewrite


Restart apache

sudo systemctl restart apache2


So, this was how host multiple websites on the same machine with Apache running on Ubuntu server. In the next guide we’ll cover how to setup SSL, which means stay tuned and see y’all in the next one.