0% found this document useful (0 votes)
85 views3 pages

How To Configure Multiple Sites With Apache

This document provides a 7-step process for configuring multiple websites with Apache on an Ubuntu 18.04 server. The steps include: 1) Creating a directory for each site, 2) Setting folder permissions, 3) Creating index pages for each site, 4) Copying the default Apache configuration file for each site, 5) Editing the configuration files to define the server name, document root, and other settings for each site, 6) Enabling the new configuration files and disabling the default, and 7) Verifying the configurations by visiting the sites. This allows multiple sites to be hosted on one server with Apache resolving requests based on the domain name.

Uploaded by

yuosef moatamedi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
85 views3 pages

How To Configure Multiple Sites With Apache

This document provides a 7-step process for configuring multiple websites with Apache on an Ubuntu 18.04 server. The steps include: 1) Creating a directory for each site, 2) Setting folder permissions, 3) Creating index pages for each site, 4) Copying the default Apache configuration file for each site, 5) Editing the configuration files to define the server name, document root, and other settings for each site, 6) Enabling the new configuration files and disabling the default, and 7) Verifying the configurations by visiting the sites. This allows multiple sites to be hosted on one server with Apache resolving requests based on the domain name.

Uploaded by

yuosef moatamedi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

How to Configure Multiple Sites with Apache

If you are hosting more than one site on a server, then you most likely use Apache’s virtual host files to
state which domain should be served out. Name based virtual hosts are one of the methods used to
resolve site requests. This means that when someone views your site the request will travel to the
server, which in turn, will determine which site’s files to serve out based on the domain name. Using this
method you’ll be able to host multiple sites on one server with the same IP. In this tutorial, we’ll show
you how to set up your virtual host file for each of your domains on an Ubuntu 18.04 VPS server.

Preflight

 Login in as root

Step 1: Make a Directory for Each Site

You’ll create a directory for each site that you’ll be hosting, within the /var/www folder.  This location
newly created location is also dubbed the document root location; you’ll need to set this path later in the
configuration file.  Sub the domain.com and domain2.com for your domain names.

mkdir -p /var/www/domain.com/public_html

mkdir -p /var/www/domain2.com/public_html

Step 2: Set Folder Permissions


chmod -R 755 /var/www

Step 3: Set up an Index Page

To see a home page you’ll want to make sure the index.html file is created for each domain.
Something as simple as “testing for domain.com” can be set within this file.

vim /var/www/domain.com/public_html/index.html

testing for domain.com

Save and quit by hitting the Escape button and typing :wq

Repeat the steps for your second domain, using the command below.

vim /var/www/domain2.com/public_html/index.html
Step 4: Copy the Config File for Each Site

Copy the default configuration file for each site, this will also ensure that you always have a default copy
for future site creation.

cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-
available/domain.com.conf

cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-
available/domain2.com.conf

Step 5: Edit the Config File for Each Site

At the bare minimum, you’ll adjust and add the highlighted lines within the <VirtualHost
*:80> and </VirtualHost> tags.

Note
ServerAlias is the alternative name for your domain, in this case and in most, you’ll put www in front of the
domain name so people can view the site by either www or non www (ServerName).

vim /etc/apache2/sites-available/domain.com.conf

<VirtualHost *:80>
ServerAdmin [email protected]
ServerName domain.com
ServerAlias www.domain.com
DocumentRoot /var/www/domain.com/public_html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Quit and Save with :wq. Repeat this process for your domain2.com.conf file, be sure to update
your ServerName, ServerAlias and DocumentRoot for your second domain.

Step 6: Enable Your Config File

Out of the box, your server is set to read the default 000-default.conf file.  But, in our previous step we
made a new config file for each domain.  So, we will need to disable the default file.

a2dissite 000-default.confTo have your server mapped to your domains you’ll need to enable
each of your newly made .conf files.

a2ensite domain.com.conf

a2ensite domain2.com.conf

We restart the Apache service to register our changes.

systemctl restart apache2


Step 7: Verify Apache Configurations

After starting Apache you now can view that the configurations are working by either editing your
/etc/host file on your computer or by editing your domain’s DNS.

After either one of these aspects are set, you’ll be able to visit your website in a browser to see the
index.html pages set in Step 3.

Liquid Web customers enjoy 24/7 support at the tip of their fingertips with our blazing fast servers. If you
find yourself stuck on a step our support team is knowledgeable on Apache configurations and can
assist!

You might also like