# How to install Apache web server on ubuntu 22.04

## [Step 1 — Installing Apache](https://www.digitalocean.com/community/tutorials/how-to-install-the-apache-web-server-on-ubuntu-22-04#step-1-installing-apache)#

Apache is available within Ubuntu’s default software repositories, making it possible to install it using conventional package management tools.

Begin by updating the local package index to reflect the latest upstream changes:

```plaintext
sudo apt update
```

Then, install the `apache2` package:

```plaintext
sudo apt install apache2
```

After confirming the installation, `apt` will install Apache and all required dependencies.

## [Step 2 — Adjusting the Firewall](https://www.digitalocean.com/community/tutorials/how-to-install-the-apache-web-server-on-ubuntu-22-04#step-2-adjusting-the-firewall)

Before testing Apache, it’s necessary to modify the firewall settings to allow outside access to the default web ports. If you followed the instructions in the prerequisites, you should have a UFW firewall configured to restrict access to your server.

During installation, Apache registers itself with UFW to provide a few application profiles that can be used to enable or disable access to Apache through the firewall.

List the `ufw` application profiles by running the following:

```plaintext
sudo ufw app list
```

Your output will be a list of the application profiles:

```plaintext
OutputAvailable applications:
  Apache
  Apache Full
  Apache Secure
  OpenSSH
```

As indicated by the output, there are three profiles available for Apache:

* `Apache`: This profile opens only port `80` (normal, unencrypted web traffic)
    
* `Apache Full`: This profile opens both port `80` (normal, unencrypted web traffic) and port `443` (TLS/SSL encrypted traffic)
    
* `Apache Secure`: This profile opens only port `443` (TLS/SSL encrypted traffic)
    

It is recommended that you enable the most restrictive profile that will still allow the traffic you’ve configured. Since you haven’t configured SSL for your server yet in this guide, you’ll only need to allow traffic on port `80`:

```plaintext
sudo ufw allow 'Apache'
```

You can verify the change by checking the status:

```plaintext
sudo ufw status
```

The output will provide a list of allowed HTTP traffic:

```plaintext
OutputStatus: active

To                         Action      From
--                         ------      ----
OpenSSH                    ALLOW       Anywhere                  
Apache                     ALLOW       Anywhere                
OpenSSH (v6)               ALLOW       Anywhere (v6)             
Apache (v6)                ALLOW       Anywhere (v6)
```

As indicated by the output, the profile has been activated to allow access to the Apache web server.

## [Step 3 — Checking your Web Server](https://www.digitalocean.com/community/tutorials/how-to-install-the-apache-web-server-on-ubuntu-22-04#step-3-checking-your-web-server)

At the end of the installation process, Ubuntu 22.04 starts Apache. The web server will already be up and running.

Make sure the service is active by running the command for the `systemd` init system:

```plaintext
sudo systemctl status apache2
```

```plaintext
Output● apache2.service - The Apache HTTP Server
     Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor prese>
     Active: active (running) since Tue 2022-04-26 15:33:21 UTC; 43s ago
       Docs: https://httpd.apache.org/docs/2.4/
   Main PID: 5089 (apache2)
      Tasks: 55 (limit: 1119)
     Memory: 4.8M
        CPU: 33ms
     CGroup: /system.slice/apache2.service
             ├─5089 /usr/sbin/apache2 -k start
             ├─5091 /usr/sbin/apache2 -k start
             └─5092 /usr/sbin/apache2 -k start
```

As confirmed by this output, the service has started successfully. However, the best way to test this is to request a page from Apache.

You can access the default Apache landing page to confirm that the software is running properly through your IP address. If you do not know your server’s IP address, you can get it a few different ways from the command line.

Try writing the following at your server’s command prompt:

```plaintext
hostname -I
```

You will receive a few addresses separated by spaces. You can try each in your web browser to determine if they work.

Another option is to use the free [`icanhazip.com`](http://icanhazip.com) tool. This is a website that, when accessed, returns your machine’s public IP address as read from another location on the internet:

```plaintext
curl -4 icanhazip.com
```

When you have your server’s IP address, enter it into your browser’s address bar:

```plaintext
http://your_server_ip
```

You will see the default Ubuntu 22.04 Apache web page as in the following:

![Apache default page](https://assets.digitalocean.com/articles/how-to-install-apache-webserver-22.04/apache-default.PNG align="left")

This page indicates that Apache is working correctly. It also includes some basic information about important Apache files and directory locations.

## [Step 4 — Managing the Apache Process](https://www.digitalocean.com/community/tutorials/how-to-install-the-apache-web-server-on-ubuntu-22-04#step-4-managing-the-apache-process)

Now that you have your web server up and running, let’s review some basic management commands using `systemctl`.

To stop your web server, run:

```plaintext
sudo systemctl stop apache2
```

Copy

To start the web server when it is stopped, run:

```plaintext
sudo systemctl start apache2
```

To stop and then start the service again, run:

```plaintext
sudo systemctl restart apache2
```

If you are simply making configuration changes, Apache can often reload without dropping connections. To do this, use the following command:

```plaintext
sudo systemctl reload apache2
```

By default, Apache is configured to start automatically when the server boots. If this is not what you want, disable this behavior by running:

```plaintext
sudo systemctl disable apache2
```

To re-enable the service to start up at boot, run:

```plaintext
sudo systemctl enable apache2
```

Apache will now start automatically when the server boots again.
