Professional Documents
Culture Documents
Install Apache On Ubuntu 20
Install Apache On Ubuntu 20
Install Apache On Ubuntu 20
20.04 LTS
Author: Vivek Gite Last updated: November 11, 2020
The Apache (also known as the “HTTPD”) web server is one of the most
popular web servers for serving dynamic and static web pages. It is free and
open-source software released under Apache License 2.0. Let us see how to
install and the Apache on Ubuntu 20.04 LTS Linux server.
Tutorial requirements
Difficulty Easy
Table of contents
1 Installing Apache 2
2 Apache 2 service management
3 UFW Firewall configuration
4 Find server IP address
5 Test Apache 2
6 Configuring Apache 2
7 Conclusion
How to install Apache on Ubuntu 20.04 LTS
Make sure your system is up to date and patched. To do that, type the
following apt command:
sudo apt update
sudo apt upgrade
To Action From
-- ------ ----
See “How To Configure Firewall with UFW on Ubuntu 20.04 LTS” for more
info.
You can also use the dig command/host command as follows to find your
public IPv4/IPv6 address from the CLI:
dig +short myip.opendns.com @resolver1.opendns.com
See How To Find My Public IP Address From Command Line On a Linux for
more info.
ETag: "2aa6-5a4ebf1b4b8bf"
Accept-Ranges: bytes
Content-Length: 10918
Vary: Accept-Encoding
Content-Type: text/html
Another option is to fire a web browser such as Chrome or Firefox and type
the URL as follows:
http://your-server-ip
http://10.105.28.158
Basic configuration
Edit the /etc/apache2/apache2.conf file, run:
sudo nano /etc/apache2/apache2.conf
At least set ServerName to 127.0.0.1 or actual name such as your-dot-com or
server IP address:
ServerName 10.105.28.9
Save and close the file. Next, edit the /etc/apache2/ports.conf file that include
list of ports to listen on Ubuntu box:
sudo nano /etc/apache2/ports.conf
By default, the Apache version 2 on Ubuntu Linux will listen on the TCP port
80 (HTTP) and 443 (HTTPS). There is no need to change them; however, if
you run many sites in Linux containers, then we change ports as follows:
########################################################################################
## Typically you don't have to change the defaults. These are for advance usage/users ##
########################################################################################
# Change HTTP port 80 to 86
Listen 86
# Change HTTPS port 443 to 449
<IfModule ssl_module>
Listen 449
</IfModule>
<IfModule mod_gnutls.c>
Listen 449
</IfModule>
You must update your virtual host/domain config to match the port number
listed in ports.conf.
d option.
-k /dev/null : Avoid creating dot files for Apache virtual domain
DocumentRoot which can expose senstive information by using
the /dev/null as alternative skeleton directory.
-s /usr/sbin/nologin : Set login shell of the new account to
/usr/sbin/nologin, so that web server user can not login into our
system using the ssh or any other method. Again this is a security
feature.
usernamehere : User name that will store files for our virtual domain
Lock the Linux user account, enter:
sudo passwd -l usernamehere
Create html folder using the mkdir command:
sudo mkdir -pv /home/my-domain-name-here/html
Create a sample html page as follows:
sudo nano /home/my-domain-name-here/html/index.html
<html>
<head>
<title>www.cyberciti.biz - welcome</title>
</head>
<body>
<h2>www.cyberciti.biz</h2>
<p>This is a test page running on:</p>
<ul>
<li>Ubuntu Linux 20.04 LTS</li>
<li>Apache 2.x</li>
</ul>
<hr>
<small>webmaster@cyberciti.biz</small>
</body>
</html>
Test config:
sudo apache2ctl configtest
You must get “Syntax OK” message and then restart the Apache server on
Ubuntu Linux:
sudo systemctl reload apache2
Set your domains’s A and AAAA records to server’s public IPv4/IPv6 address
and test it:
http://my-domain-name-here
http://www.cyberciti.biz