How To Install Apache2 on Linux Ubuntu

You are here:
< All Topics

This article explains the procedure for installing apache2 on Linux Ubuntu version 20.


apt install apache2
Next, create an initial virtual host entry in the /etc/apache2/sites-available/ file
<VirtualHost *:80>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
You can check the config with:
apachectl configtest
Next, enable the configuration:
systemctl start apache2
This config can then be used to obtain an SSL certificate from Let’s Encrypt. See further below. 
Important Note re HTTPS and ssh 
My server is using the sslh multiplexer daemon, this uses incoming port 443 for both ssh and https.
This is to avoid ssh connection problems when trying to connect to the server from outgoing routers which do not permit outgoing ssh port 22 connections (some routers block this. If you have administrator access to the router you can modify this, but if you don’t then a workaround is to use port 443 for outgoing ssh connections, since port 443 is hardly ever blocked by routers and can thus be relied upon to be accessible).
On my server, incoming port 443 ssh connections are therefore redirected to sshd on port 22, while incoming https 443 connections are redirected to https port 444 on apache.
Thus apache must be configured to listen on port 444 instead of the default 443.
Note that some programs, such as Lets Encrypt’s SSL Certbot automatically define the https port as the default 443, so you need to remove this and set it to 444, otherwise apache will not start.
Apache ports.conf needs to look like this. Note that port 443 is not used:
root@gemini:/etc/apache2# cat ports.conf
# If you just change the port or add more ports here, you will likely also
# have to change the VirtualHost statement in
# /etc/apache2/sites-enabled/000-default.conf
Listen 80 

<IfModule mod_ssl.c>
#Listen 443
Listen 444
The sites-enabled will also use 444 instead of 443 for virtual host definitions:
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/
SSLCertificateKeyFile /etc/letsencrypt/live/

Table of Contents