Web Service
Install Apache
After updating the repositories, let's install the Apache package
sudo apt update
sudo apt full-upgrade
sudo apt install apache2
Check that Apache module is running, and that it is listening at least to the port 80 with:
sudo systemctl status apache2
sudo ss -ltpn
In a separate web browser, visit your IP address or host domain name to see your Apache default page:
Set up Virtual Hosts
To host different domains or subdomains, create the relevant folder inside the directory /var/www/
sudo mkdir /var/www/yourdomain
Create a simple webpage inside the folder with the nano
editor:
sudo nano /var/www/yourdomain/index.html
and paste this HTML snippet:
<html>
<head>
<title>Welcome to yourdomain!</title>
</head>
<body>
<h1>Success! The yourdomain server block is working!</h1>
</body>
</html>
Then create a virtual host file with the following configuration block
sudo nano /etc/apache2/sites-available/yourdomain.conf
<VirtualHost *:80>
ServerAdmin webmaster@yourdomain.tld
ServerName yourdomain.tld
ServerAlias www.yourdomain.tld
DocumentRoot /var/www/yourdomain
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Then enable the virtual host:
sudo a2ensite yourdomain.conf
Disable any default host configurations, reload Apache and check that all is OK:
sudo a2dissite defaultdomains.conf
sudo systemctl reload apache2
sudo apache2ctl configtest
Note the "Not secure" message!
Register for SSL/TLS
You will surely be interested in offering secure browsing to your visitors, so we install a light certification bot:
sudo apt install python3-certbot-apache
and set up a certification with:
sudo certbot --apache -d yourdomain.tld
Now you can refresh the web browser and will see that the website is encrypted:
Your website is now secured!