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
ServerName site1.example.net
ServerAlias site1
ServerAdmin your_email@example.net
</VirtualHost *:80

And paste the following into site2.conf

<VirtualHost *:80>
DocumentRoot /var/www/html/site2.conf
ServerName site2.example.net
ServerAlias site2
ServerAdmin your_email@example.net
</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:
<html>
<head>
<title>Site</title>
</head>
<body>
<h1>This is a site</h1>
</body>
</html>

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:
127.0.1.1 site1
127.0.2.1 site2

Step 5, enable your websites

Type the following command into your terminal:

sudo a2ensite site1.conf site2.conf

Leave a comment

Discover more from Stidmatt

Subscribe now to keep reading and get access to the full archive.

Continue reading