Install the Apache webserver on Ubuntu Linux
Apache Web Server is a software package that turns a computer into an HTTP server.
That is, it sends web pages – stored as HTML files – to people on the internet who request them. It is open-source software, which means it can be used and modified freely.
Installation
Refresh your local software package database to make sure you are accessing the latest versions
sudo apt-get update
Install Apache 2
sudo apt-get install apache2
Configure Your Firewall
sudo ufw app list
Output:
Available applications:
Apache
Apache Full
Apache Secure
OpenSSH
Allow normal web traffic on port 80
sudo ufw allow 'Apache'
Verify the changes by checking UFW status
sudo ufw status
Apache Service Controls
This operation uses the systemctl command, with a series of switches:
Stop Apache:
sudo systemctl stop apache2.service
Start Apache:
sudo systemctl start apache2.service
Restart Apache:
sudo systemctl restart apache2.service
Reload Apache:
sudo systemctl reload apache2.service
Apache Configuration Files and Directories
Directories
After installing, Apache by default creates a document root directory at /var/www/html.
Configuration Files
Apache creates log files for any errors it generates in the file /var/log/apache2/error.log.
It also creates access logs for its interactions with clients in the file /var/log/apache2/access.log.
Like many Linux-based applications, Apache functions through the use of configuration files.
They are all located in the /etc/apache2/ directory.
/etc/apache2/apache2.conf – This is the main Apache configuration file and controls everything Apache does on your system.
Changes here affect all the websites hosted on this machine.
/etc/apache2/ports.conf – The port configuration file.
You can customize the ports Apache monitors using this file.
By default, Port 80 is configured for http traffic.
/etc/apache2/sites-available – Storage for Apache virtual host files.
A virtual host is a record of one of the websites hosted on the server.
/etc/apache2/sites-enabled – This directory holds websites that are ready to serve clients.
The a2ensite command is used on a virtual host file in the sites-available directory to add sites to this location.