In our previous article, we have configured two sample sites testing.com and example.com on ubuntu 18.04 server. You can check it at Host Multiple Websites on an Ubuntu 18.04 Server Part-I. At last, we have added sample web contents for each of the domains in the index.html file. Let’s see further steps to follow and complete this configuration.
Create the virtual hosts configuration files for our two sites
When Apache is first installed on Ubuntu 18.04 server, it creates a default virtual host file at /etc/apache2/sites-available/000-default.conf.
We need to copy that file and use it to configure our testing.com and example.com virtual hosts. To do this, run
command on a terminal window:
$ sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/testing.com.conf
$ sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/example.com.conf
Apache configuration files by default end with a “.config” file extension.
Once you have copied the files, open the first virtual hosts file with a nano editor to edit its content using below
$ sudo nano /etc/apache2/sites-available/testing.com.conf
Then you have to overwrite the values with the text below:
- <VirtualHost *:80>
- ServerAdmin admin@testing.com
- ServerName testing.com
- ServerAlias www.testing.com
- DocumentRoot /var/www/testing.com/public_html
- ErrorLog ${APACHE_LOG_DIR}/error.log
- CustomLog ${APACHE_LOG_DIR}/access.log combined
- </VirtualHost>
As you can see above, we have referenced the directory /var/www/testing.com/public_html as a document root because that will be the place where we will save our testing.com website’s files.
We need to follow the same procedure for our example.com virtual host
$ sudo nano /etc/apache2/sites-available/example.com.conf
Then overwrite the files with the following contents:
- <VirtualHost *:80>
- ServerAdmin admin@example.com
- ServerName example.com
- ServerAlias www.example.com
- DocumentRoot /var/www/example.com/public_html
- ErrorLog ${APACHE_LOG_DIR}/error.log
- CustomLog ${APACHE_LOG_DIR}/access.log combined
- </VirtualHost>
Enable the two virtual hosts
We created two configuration files for our domains. Now, we need to enable them using the following commands:
$ sudo a2ensite testing.com.conf
$ sudo a2ensite example.com.conf
Restart Apache for the changes to take effect
Once you add a virtual host on your Ubuntu 18.04 server, you will need to restart apache service using below command :
$ sudo service apache2 restart
Edit the local hosts file on your computer
Your virtual hosts should be up and running without any issues. However because we used dummy values for testing purposes, we need to edit our local
If you are running Linux then you need to edit the /etc/hosts file using the command below:
$ sudo nano /etc/hosts
Then add the below entries to the file and save.
- 111.111.111.111 example.com
- 111.111.111.111 testing.com
On

Make sure you have replace 111.111.111.111 with the real public IP address of your server.
Test your virtual hosts on your browser
Finally, you need to access example.com and testing.com from your browser and if you followed the steps correctly, you should see the content we created for the virtual hosts as shown below.
Example.com

That’s all! We are done with the setup of these two websites on a single Ubuntu 18.04 server. Remember, you can replicate this idea to host an unlimited number of virtual hosts.