Commands to install Apache web server on Ubuntu 22.04 or 20.04 LTS

If you want to learn how to run and access a website from a remote location, we need a web server and what is more convenient than getting started with Apache if you are new to the world of IT. accommodation. Here in this tutorial we will learn the command to install and start Apache web server on Ubuntu 22.04 LTS Jammy JellyFish or Ubuntu 20.04 LTS focal fossa.

Apache is the most widely used web server on the Internet. And can be easily configured due to its flexible nature and ability to expand functionality using a large number of modules. It was developed and maintained under the Apache foundation.

Usually the Apache web server is installed with PHP and MySQL / MariaDB. However, Apache itself only provides static HTML pages. However, when combined with PHP (PHP Hypertext Preprocessor) as a scripting language, it can serve dynamic HTML pages generated from database content.

Most popular content management systems (CMS) like WordPress or Joomla therefore also need PHP and MySQL database. And when it comes to installing Apache, all popular Linux distributions like RedHat, CentOS, Ubuntu Debian and others have Apache packages in their respective base repository, so the user can install it with just one command. We can use Apache on Windows but being an open source project and native to Linux systems and their dominance in the server world, hosting services only offer it on Linux to get the full potential of this web server software. .

While these developers are on Windows and working on a web project that requires Apache, typically go with XAMPP or WampServer, like projects, to get the entire LAMP stack up and running easily.

Steps to Install Apache Web Server on Ubuntu 22.04 | 20.04 LTS

What do you need to complete the steps in this tutorial?

• Ubuntu server 22.04 | 20.4 | 18.04
• A non-root user with sudo rights
• Internet connection

1. Updating Apt

If you just installed a new Ubuntu server on your local machine, Cloud, or a VPS, run the system update command first. This will refresh the repository cache as well as the installation if any updates are available for your system.

sudo apt update

2. Command to install Apache on Ubuntu 22.04 | 20.04 LTS

Then, as mentioned at the beginning of the tutorial, we don’t need to add any third-party repository because the package to install Apache web server is already in the ubuntu Linux base repository.

sudo apt install apache2

3. Start and activate the Apache service

After the installation is complete, first check whether the Apache service is already running in the background or not using the given command:

systemctl status apache2

If it is not running, start and activate it with this command:

sudo systemctl enable --now apache2

4. Allow port 80/443 on Ubuntu 22.04 | 04/20

Depending on where you installed your Ubuntu 20.04 / 22.04 server, we need to open the firewall for two ports 80 for HTTP and 443 for HTTPS. If you are in the cloud, use your service provider’s network firewall to open these ports. Whereas, in case the system also has the firewall enabled, run:

Check whether the system firewall is active or not.

sudo ufw status

If the output is’active‘then run

sudo ufw allow 80/tcp
sudo ufw allow 443/tcp

5. Go to the demo web page

Now that the Apache web server is up and running, it’s time to go to its demo webpage to confirm that everything is working as smoothly as we want it to be.

Open your browser to a system that can access the IP address or domain where you installed Apache. And point it to url as given syntax:


To replace the Server IP address with the real IP address of your Ubuntu server 22.04 or 20.04. If you do not know the address, run in the command terminal of your server:

ip a

Reload the Restart or Stop Apache commands

There are many scenarios where after installing a web application we need to restart or stop the Apache web server service. And if you are in one of those scenarios, here are the commands to follow:

• To recharge : This means the web server stays running, but just refresh or reload the configuration file.

sudo systemctl reload apche2

• To restart normally: In this case, Apache will quit the process threads when they are terminated and inactive, then reload the configuration.

sudo /etc/init.d/apache2 graceful

• Restart: This will kill all threads, stop the web server and restart it.

sudo systemctl restart apache2

• Stop: Completely close the web server service.

sudo systemctl stop apache2

• To start:

sudo systemctl start apache2

• To deactivate Apache to start automatically with system startup, use:

sudo systemctl disable apache2

Whereas to reactivate it:

sudo systemctl enable apache2

Completely uninstall Apache from Ubuntu 22.04 or 20.04

To completely remove the web server, if you don’t need it, run:

sudo apt remove apache2*

For more information, see the official Apache documentation while to learn more see how to install WordPress on an Apache server running on CentOS / AlmaLinux / Rocky / RHEL / Oracle

Comments are closed.