How Can We Help?

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/kevwells.com.conf file
 
<VirtualHost *:80>
ServerName kevwells.com
ServerAlias www.kevwells.com
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
 
You can check the config with:
 
apachectl configtest
 
Next, enable the configuration:
 
a2ensite kevwells.com.conf
 
then
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
</IfModule>
 
The sites-enabled will also use 444 instead of 443 for virtual host definitions:
 
<VirtualHost 127.0.0.1:444>
 
ServerName kevwells.com
ServerAlias www.kevwells.com
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/kevwells.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/kevwells.com/privkey.pem
 
</VirtualHost>
</IfModule> 

Table of Contents