You are on page 1of 22

12/04/2021 How to Install Apache Web Server on Ubuntu 20.

04

 Menu

 Menu 

How to Install Apache Web Server on Ubuntu


20.04

Aaron Kili Last Updated: July 3, 2020 Apache, Ubuntu 1 Comment

This guide will take you through the installation of the Apache webserver on Ubuntu
20.04. It includes managing the Apache2 services, open webserver port in the rewall,
testing the Apache2 installation, and con guring a Virtual Host environment.

Related Read: How to Install Nginx Web Server on Ubuntu 20.04

Requirements:

How to Install Ubuntu 20.04 Server

Installing Apache2 in Ubuntu 20.04 

https://www.tecmint.com/install-apache-web-server-on-ubuntu-20-04/ 1/22
12/04/2021 How to Install Apache Web Server on Ubuntu 20.04

1. First, log into your Ubuntu 20.04 system and update your system packages using the
following apt command.

$ sudo apt update

2. Once the update process is complete, install the Apache2 web server software as
follows.

$ sudo apt install apache2

Install Apache on Ubuntu 20.04

3. While installing the Apache2 package, the installer triggers systemd to automatically
start and enable the apache2 service. You can verify that the apache2 service is
active/running and is enabled to automatically start at system startup using the following
systemctl commands.

$ sudo systemctl is-active apache2


$ sudo systemctl is-enabled apache2 
$ sudo systemctl status apache2

https://www.tecmint.com/install-apache-web-server-on-ubuntu-20-04/ 2/22
12/04/2021 How to Install Apache Web Server on Ubuntu 20.04

Check Apache Service in Ubuntu 20.04

Managing the Apache in Ubuntu 20.04

4. Now that your apache web server is running, it’s time to learn some basic management
commands to manage the apache process using the following systemctl commands.

$ sudo systemctl stop apache2 #stop apache2


$ sudo systemctl start apache2 #start apache2
$ sudo systemctl restart apache2 #restart apache2
$ sudo systemctl reload apache2 #reload apache2
$ sudo systemctl disable apache2 #disable apache2
$ sudo systemctl enable apache2 #enable apache2

Con guring Apache in Ubuntu 20.04


5. All Apache2 con guration les are stored in the /etc/apache2 directory, you can
view all les and subdirectories under it with the following ls command.

https://www.tecmint.com/install-apache-web-server-on-ubuntu-20-04/ 3/22
12/04/2021 How to Install Apache Web Server on Ubuntu 20.04

$ ls /etc/apache2/*

View Apache Con guration Files

6. The following are the key con guration les and sub-directories you should take note
of:

/etc/apache2/apache2.conf – The main Apache global con guration le, that


includes all other con guration les.
/etc/apache2/conf-available – stores available con gurations.
/etc/apache2/conf-enabled – contains enabled con gurations.
/etc/apache2/mods-available – contains available modules.
/etc/apache2/mods-enabled – contains enabled modules.
/etc/apache2/sites-available – contains con guration le for available sites (virtual
hosts).
/etc/apache2/sites-enabled – contains con guration le for enabled sites (virtual
hosts).

Note that if the server’s FQDN is not set globally, you will get the following warning every
time you check the apache2 service status or run a con guration test.

apachectl[2996]: AH00558: apache2: Could not reliably determine the server

Set the 'ServerName' directive globally in the main apache con guration le to
suppress this message. 

https://www.tecmint.com/install-apache-web-server-on-ubuntu-20-04/ 4/22
12/04/2021 How to Install Apache Web Server on Ubuntu 20.04

Apache Server Name Error

7. To set the web server’s FQDN, use the ServerName directive in


/etc/apache2/apache2.conf le, open it for editing using your favorite text editor.

$ sudo vim /etc/apache2/apache2.conf

Add the following line in the le (replacing webserver1.tecmint.com with your FQDN).

ServerName webserver1.tecmint.com

Set Server FQDN in Apache

Set Server FQDN in Apache

8. After adding the server name in the apache con guration, check the con guration
syntax for correctness, and restart the service.

$ sudo apache2ctl configtest


$ sudo systemctl restart apache2

https://www.tecmint.com/install-apache-web-server-on-ubuntu-20-04/ 5/22
12/04/2021 How to Install Apache Web Server on Ubuntu 20.04

Check Apache Con guration

Check Apache Con guration

9. Now when you check the apache2 service status, the warning should not appear.

$ sudo systemctl status apache2

Check Apache Service Status

Opening Apache Ports in UFW Firewall


10. If you have the UFW rewall enabled and running on your system, you need to open
the HTTP (port 80) and HTTPS (port 443) services in the rewall con guration, to allow
web traf c to the Apache2 web server via the rewall.

$ sudo ufw allow http


$ sudo ufw allow https
$ sudo ufw reload
OR
$ sudo ufw allow 80/tcp
$ sudo ufw allow 443/tcp
$ sudo ufw reload


Testing Apache on Ubuntu 20.04
https://www.tecmint.com/install-apache-web-server-on-ubuntu-20-04/ 6/22
12/04/2021 How to Install Apache Web Server on Ubuntu 20.04

11. To test if the Apache2 webserver installation is working ne, open a web browser, and
use your server’s IP address to navigate:

http://SERVER_IP

To nd out your server’s public IP address, use any of the following curl commands.

$ curl ifconfig.co
OR
$ curl ifconfig.me
OR
$ curl icanhazip.com

Find Server IP in Ubuntu 20.04

If you see the Apache Ubuntu default welcome web page, it means your web server
installation is working ne.

https://www.tecmint.com/install-apache-web-server-on-ubuntu-20-04/ 7/22
12/04/2021 How to Install Apache Web Server on Ubuntu 20.04

Apache2 Default Page

Setting Up Virtual Hosts in Ubuntu 20.04


Although the Apache2 web server is con gured by default to host one website, you can
use it to host multiple web sites/applications using the concept of “Virtual Host”.

Therefore Virtual Host is a term that refers to the practice of running more than one web
site/application (such as example.com and example1.com) on a single server.

Additionally, Virtual Hosts can be “name-based “(meaning that you have multiple
domain/hostnames running on a single IP address), or “IP-based” (meaning that you have
a different IP address for every web site).

Note that the default virtual host which serves the Apache Ubuntu default welcome web
page which is used to test the Apache2 installation is located in the /var/www/html
directory.

$ ls /var/www/html/

https://www.tecmint.com/install-apache-web-server-on-ubuntu-20-04/ 8/22
12/04/2021 How to Install Apache Web Server on Ubuntu 20.04

12. For this guide, we will create a virtual host for the web site called
linuxdesktop.info . So let’s rst create the web document root for the site which will
store the site’s web les.

$ sudo mkdir -p /var/www/html/linuxdesktop.info

13. Next, set the appropriate ownership and permissions on the created directory.

$ sudo chown www-data:www-data -R /var/www/html/linuxdesktop.info


$ sudo chmod 775 -R /var/www/html/linuxdesktop.info

14. Now create a sample index page for testing purposes.

$ sudo vim /var/www/html/linuxdesktop.info/index.html

Copy and paste the following html code in it.

<html>
<head>
<title>Welcome to linuxdesktop.info!</title>
</head>
<body>
<h1>Congrats! The new linuxdesktop.info virtual host is working fine.<
</body>
</html>

Save the le and exit it.

15. Next, you need to create a virtual host con guration le (which should end with the
.conf extension) for the new site under the /etc/apache2/sites-available directory.


$ sudo vim /etc/apache2/sites-available/linuxdesktop.info.conf
https://www.tecmint.com/install-apache-web-server-on-ubuntu-20-04/ 9/22
12/04/2021 How to Install Apache Web Server on Ubuntu 20.04

Then copy and paste the following con guration it the le (remember to replace
www.linuxdesktop.info with your FQDN).

<VirtualHost *:80>
ServerName www.linuxdesktop.info
ServerAlias linuxdesktop.info
DocumentRoot /var/www/html/linuxdesktop.info
ErrorLog /var/log/apache2/linuxdesktop.info_error.log
CustomLog /var/log/apache2/linuxdesktop.info_access.log combined
</VirtualHost>

Save the le and exit it.

16. Next, enable the new site and reload the Apache2 con guration to apply the new
changes as follows.

$ sudo a2ensite linuxdesktop.info.conf


Learn Linux in One Week and Go From Zero to Hero - Get This Book
$ sudo systemctl reload apache2

17. Finally, test if the new virtual host con guration is working ne. In a web browser, use
your FQDN to navigate.

http://domain-name

If you can see the index page for your new website, it means the virtual host is working
ne.


Check Virtual Host in Apache
https://www.tecmint.com/install-apache-web-server-on-ubuntu-20-04/ 10/22
12/04/2021 How to Install Apache Web Server on Ubuntu 20.04

That’s all! In this guide, we have shown how to install the Apache webserver on Ubuntu
20.04. We also covered how to manage the Apache2 services, open the HTTP and HTTPS
services/ports in the UFW rewall, tested the Apache2 installation, and con gured and
tested a Virtual Host environment. Do you have any queries, use the comment form below
to reach us.

 Apache Tips , Ubuntu Tips

 How To Install Linux Mint 20 “Ulyana” How to Install Nginx Web Server on
Ubuntu 20.04 

If you liked this article, then do subscribe to email alerts for Linux tutorials. If you have
any questions or doubts? do ask for help in the comments section.

If You Appreciate What We Do Here On TecMint, You


Should Consider:

TecMint is the fastest growing and most trusted community site for
any kind of Linux Articles, Guides and Books on the web. Millions of
people visit TecMint! to search or browse the thousands of published
articles available FREELY to all.

If you like what you are reading, please consider buying us a coffee (
or 2 ) as a token of appreciation.

https://www.tecmint.com/install-apache-web-server-on-ubuntu-20-04/ 11/22
12/04/2021 How to Install Apache Web Server on Ubuntu 20.04

We are thankful for your never ending support.

Related Posts

How to Speed Up Apache with Varnish Cache on CentOS 7

https://www.tecmint.com/install-apache-web-server-on-ubuntu-20-04/ 12/22
12/04/2021 How to Install Apache Web Server on Ubuntu 20.04

GoAccess (A Real-Time Apache and Nginx) Web Server Log Analyzer

https://www.tecmint.com/install-apache-web-server-on-ubuntu-20-04/ 13/22
12/04/2021 How to Install Apache Web Server on Ubuntu 20.04

How to Monitor Apache Performance Using mod_status in Ubuntu

https://www.tecmint.com/install-apache-web-server-on-ubuntu-20-04/ 14/22
12/04/2021 How to Install Apache Web Server on Ubuntu 20.04

Protect Apache Against Brute Force or DDoS Attacks Using Mod_Security and
Mod_evasive Modules

https://www.tecmint.com/install-apache-web-server-on-ubuntu-20-04/ 15/22
12/04/2021 How to Install Apache Web Server on Ubuntu 20.04

“Forbidden – You don’t have permission to access / on this server” Error

How to Enable HTTP/2 in Apache on Ubuntu

1 thought on “How to Install Apache Web Server


on Ubuntu 20.04”

aktarus 
November 10, 2020 at 6:19 pm
https://www.tecmint.com/install-apache-web-server-on-ubuntu-20-04/ 16/22
12/04/2021 How to Install Apache Web Server on Ubuntu 20.04

Very very goog. Great explanation :)

Reply

Got something to say? Join the discussion.


Have a question or suggestion? Please leave a comment to start the discussion. Please
keep in mind that all comments are moderated and your email address will NOT be
published.

Name *

Email *

Website

Save my name, email, and website in this browser for the next time I comment.

Notify me of followup comments via e-mail. You can also subscribe without
commenting.

Post Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

https://www.tecmint.com/install-apache-web-server-on-ubuntu-20-04/ 17/22
12/04/2021 How to Install Apache Web Server on Ubuntu 20.04

Over 3,500,000+ Readers

A Beginners Guide To Learn Linux for Free [with Examples]

https://www.tecmint.com/install-apache-web-server-on-ubuntu-20-04/ 18/22
12/04/2021 How to Install Apache Web Server on Ubuntu 20.04

Red Hat RHCSA/RHCE 8 Certi cation Study Guide [eBooks]

Linux Foundation LFCS and LFCE Certi cation Study Guide [eBooks]

https://www.tecmint.com/install-apache-web-server-on-ubuntu-20-04/ 19/22
12/04/2021 How to Install Apache Web Server on Ubuntu 20.04

Learn Linux Commands and Tools

Real Time Interactive IP LAN Monitoring with IPTraf Tool

11 Lesser Known Useful Linux Commands

6 Best CLI Tools to Search Plain-Text Data Using Regular Expressions

Newsboat – An RSS/Atom Feed Reader for Linux Terminals

How to Keep ‘sudo’ Password Timeout Session Longer in Linux

Difference Between su and sudo and How to Con gure sudo in Linux

https://www.tecmint.com/install-apache-web-server-on-ubuntu-20-04/ 20/22
12/04/2021 How to Install Apache Web Server on Ubuntu 20.04

If You Appreciate What We Do Here On TecMint, You Should Consider:

Linux Server Monitoring Tools

systemd-analyze – Find System Boot-up Performance Statistics in Linux

bmon – A Powerful Network Bandwidth Monitoring and Debugging Tool for Linux

How to Use ‘fsck’ to Repair File System Errors in Linux

https://www.tecmint.com/install-apache-web-server-on-ubuntu-20-04/ 21/22
12/04/2021 How to Install Apache Web Server on Ubuntu 20.04

How to Setup and Manage Log Rotation Using Logrotate in Linux

How to Add Hosts in OpenNMS Monitoring Server

CloudStats.me – Monitors Your Linux Servers and Websites from the Cloud

Learn Linux Tricks & Tips

How to Send a Message to Logged Users in Linux Terminal

Understanding Different Classi cations of Shell Commands and Their Usage in


Linux

Bash-it – Bash Framework to Control Your Scripts and Aliases

How to Manipulate Filenames Having Spaces and Special Characters in Linux

Rename All Files and Directory Names to Lowercase in Linux

How to Auto Execute Commands/Scripts During Reboot or Startup

Best Linux Tools

Best Command Line HTTP Clients for Linux

4 Best Linux Apps for Downloading Movie Subtitles

10 Top Open Source Caching Tools for Linux in 2020

27 Best IDEs for C/C++ Programming or Source Code Editors on Linux

7 Best Calendar Apps for Linux Desktop in 2020

9 Best Twitter Clients for Linux That You Will Love to Use

Donate to TecMint Contact Us Advertise on TecMint Linux Services Copyright Policy

Privacy Policy Career Sponsored Post

Tecmint: Linux Howtos, Tutorials & Guides © 2021. All Rights Reserved.
The material in this site cannot be republished either online or of ine, without our permission.

Hosting Sponsored by : Linode Cloud Hosting


https://www.tecmint.com/install-apache-web-server-on-ubuntu-20-04/ 22/22

You might also like