Apache is a popular open-source, cross-platform web server that is, by the numbers, the most popular web server in existence.
What you’ll learn
How to set up Apache
Create different websites and host them on localhost
What you’ll need
Any Linux distribution
Secure Shell (SSH) access to your server or Linux server running on Virtualbox or VMware
Installing Apache server
To install Apache server type the following command
sudo apt update && sudo apt install apache2
After installing the packages. Type localhost or 127.0.0.1 in your web-browser for this page
If the above page is shown, the Apache server is up and running.
Creating your own website
The Apache2 default page is found in index.html page in /var/www/html. We can modify the existing index.html page to our needs, but that will be inefficient
So instead under /var/www/<your_domain> we create a new index.html file
So let’s start by creating a folder for our new website in /var/www/ by running
sudo mkdir /var/www/food
sudo touch /var/www/food/index.html
To modify my index.html file I will be using a text editor called "Gedit". To install gedit
sudo apt install gedit
P.S: you can use nano or vi/vim to edit the files as well
After installing gedit
sudo gedit /var/www/food/index.html
Paste the following code
<html>
<head>
<title> Food menu </title>
</head>
<body>
<p> I'm running this food website on an Ubuntu Server!
</body>
</html>
Setting up the VirtualHost Configuration File
We start this step by going into the configuration files directory and make a new configuration file:
sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/food.conf
Now edit the food.conf file by adding these lines below as shown in the image
Activating VirtualHost file
After setting up our website, we need to activate the virtual hosts configuration file to enable it. We do that by running the following command in the configuration file directory:
cd /etc/apache2/sites-available
sudo a2ensite food.conf
After enabling the virtual hosts we need to reload the apache2 server
sudo systemctl reload apache2
After restarting the server. Go to your web browser and type the server name which in this case as configured was "food.example.com". This should be the result shown
Conclusion
This was a simple setup for a web server for multiple websites. If you run into any issues please let me know in the comments below