Build an Apache Server on Ubuntu

We are going to host two different websites on an Apache Server running Ubuntu.

Step 1, install packages

sudo apt-get install apache2

Step 2, create your conf files

Create two conf files in /etc/apache2/sites-available

Call them site1.conf and site2.conf

Create links using ln-s to both of those conf files in /etc/apache2/sites-enabled

sudo ln -s /etc/apache2/sites-available/site1.conf /etc/apache2/sites-enabled/.

sudo ln -s /etc/apache2/sites-available/site2.conf /etc/apache2/sites-enabled

Paste the following into site1.conf

<VirtualHost *:80>
DocumentRoot /var/www/html/site1.conf
ServerAlias site1
</VirtualHost *:80

And paste the following into site2.conf

<VirtualHost *:80>
DocumentRoot /var/www/html/site2.conf
ServerAlias site2
</VirtualHost *:80

Step 3, create your landing pages

Create two folders in your home directory. Call them site1 and site2

Inside each of them create a file called index.php

Paste the following into each of  those files:
<h1>This is a site</h1>

Change these in any way you want.

Create a symbolic link to each of those folders in /var/www/html

Step 4, modify your hosts file

Add the following lines to the end of  your /etc/hosts file: site1 site2

Step 5, enable your websites

Type the following command into your terminal:

sudo a2ensite site1.conf site2.conf

Leave a Reply

Your email address will not be published. Required fields are marked *