> ## Documentation Index
> Fetch the complete documentation index at: https://help.freakhosting.com/llms.txt
> Use this file to discover all available pages before exploring further.

# How to Install Apache on Ubuntu, Debian and AlmaLinux

> Install Apache on Ubuntu 24.04 with sudo apt install apache2 (httpd on AlmaLinux/Rocky), open port 80, add a virtual host and test with apache2ctl configtest.

To install Apache on Ubuntu 24.04 or Debian 13, run `sudo apt update && sudo apt install apache2`. On AlmaLinux or Rocky Linux the package is called `httpd`: run `sudo dnf install httpd` and `sudo systemctl enable --now httpd`. Allow port 80 (and 443 for HTTPS) in your firewall, then open your server's IP in a browser to see the default test page.

| Difficulty | Time | Works on | Needs |
| - | - | - | - |
| Beginner | 10 minutes | Ubuntu 22.04 / 24.04, Debian 12 / 13, AlmaLinux / Rocky 9 / 10 | SSH access with sudo |

## Before you start

* Connect with [SSH](https://help.freakhosting.com/portals/other/how-to-connect-to-a-linux-server-with-ssh.md) as a user with `sudo` rights. If you are `root`, leave out `sudo`.
* Make sure nothing else uses port 80, such as Nginx. Only one web server can listen on a port.

Apache HTTP Server is a web server: it answers browser requests and serves your site's files. Ubuntu and Debian call the package and service `apache2`; AlmaLinux and Rocky call them `httpd`.

## How to install Apache

> [tab] Ubuntu / Debian
>
> **1. Install the package**
>
> ```bash theme={null}
> sudo apt update
> sudo apt install apache2
> ```
>
> Apache starts and is enabled at boot automatically.
>
> **2. Check the service**
>
> ```bash theme={null}
> systemctl status apache2
> ```
>
> Look for `active (running)`.

> [tab] AlmaLinux / Rocky
>
> **1. Install the package**
>
> ```bash theme={null}
> sudo dnf install httpd
> ```
>
> **2. Start Apache and enable it at boot**
>
> ```bash theme={null}
> sudo systemctl enable --now httpd
> ```
>
> **3. Check the service**
>
> ```bash theme={null}
> systemctl status httpd
> ```

## How to open the firewall for Apache

> [tab] Ubuntu / Debian (ufw)
>
> ```bash theme={null}
> sudo ufw allow 80/tcp
> sudo ufw allow 443/tcp
> ```
>
> On Ubuntu the profile `sudo ufw allow 'Apache Full'` opens both ports.

> [tab] AlmaLinux / Rocky (firewalld)
>
> ```bash theme={null}
> sudo firewall-cmd --permanent --add-service=http --add-service=https
> sudo firewall-cmd --reload
> ```

> [!WARNING]
>
> If your firewall is not active yet, allow SSH before you enable it. See [set up ufw](https://help.freakhosting.com/portals/other/how-to-set-up-a-firewall-with-ufw.md) or [set up firewalld](https://help.freakhosting.com/portals/other/how-to-set-up-a-firewall-with-firewalld.md).

## Where are the Apache files?

| What | Ubuntu / Debian | AlmaLinux / Rocky |
| - | - | - |
| Main config | `/etc/apache2/apache2.conf` | `/etc/httpd/conf/httpd.conf` |
| Site configs | `/etc/apache2/sites-available/`, enabled with `a2ensite` | `/etc/httpd/conf.d/*.conf` |
| Default site | `/etc/apache2/sites-available/000-default.conf` | Test page shown when `/var/www/html` is empty |
| Web root | `/var/www/html` | `/var/www/html` |
| Logs | `/var/log/apache2/` | `/var/log/httpd/` |
| Test config | `sudo apache2ctl configtest` | `sudo apachectl configtest` |

## How to add a virtual host for your domain

A virtual host lets one Apache server answer for a specific domain. This example uses `example.com`.

**1. Create the web root**

```bash theme={null}
sudo mkdir -p /var/www/example.com/public_html
echo '<h1>example.com works</h1>' | sudo tee /var/www/example.com/public_html/index.html
```

**2. Create the config file**

On Ubuntu / Debian create `/etc/apache2/sites-available/example.com.conf`. On AlmaLinux / Rocky create `/etc/httpd/conf.d/example.com.conf`.

```apache theme={null}
<VirtualHost *:80>
    ServerName example.com
    ServerAlias www.example.com
    ServerAdmin you@example.com
    DocumentRoot /var/www/example.com/public_html

    <Directory /var/www/example.com/public_html>
        AllowOverride All
        Require all granted
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/example.com-error.log
    CustomLog ${APACHE_LOG_DIR}/example.com-access.log combined
</VirtualHost>
```

On AlmaLinux / Rocky, `${APACHE_LOG_DIR}` is not defined. Use `/var/log/httpd/example.com-error.log` and `/var/log/httpd/example.com-access.log` instead.

**3. Enable the site (Ubuntu / Debian only)**

```bash theme={null}
sudo a2ensite example.com.conf
sudo a2dissite 000-default.conf
sudo a2enmod rewrite
```

`a2enmod rewrite` turns on `mod_rewrite`, which most PHP apps need for clean URLs.

**4. Test and reload**

```bash theme={null}
sudo apache2ctl configtest     # Ubuntu / Debian
sudo systemctl reload apache2
```

```bash theme={null}
sudo apachectl configtest      # AlmaLinux / Rocky
sudo systemctl reload httpd
```

> [!NOTE]
>
> On AlmaLinux / Rocky with SELinux enforcing, files under `/var/www/` work as they are. If you put a site anywhere else, give it the `httpd_sys_content_t` label with `semanage fcontext` and `restorecon`. See [SELinux on AlmaLinux and Rocky](https://help.freakhosting.com/portals/other/how-to-use-selinux-on-almalinux-and-rocky.md).

## How to check it worked

`configtest` should print:

```text theme={null}
Syntax OK
```

A warning `AH00558: Could not reliably determine the server's fully qualified domain name` is harmless. To silence it, add `ServerName example.com` to the main config.

List the sites Apache loaded (Ubuntu / Debian):

```bash theme={null}
sudo apache2ctl -S
```

You should see a line such as `*:80 example.com (/etc/apache2/sites-enabled/example.com.conf:1)`. Once your domain's DNS points to the server ([point a domain](https://help.freakhosting.com/portals/other/how-to-point-a-domain-to-your-server.md)), open `http://example.com`.

## Frequently asked questions

### What is the difference between apache2 and httpd?

They are the same Apache HTTP Server. Debian-based systems name it `apache2`; Red Hat-based systems name it `httpd`. Paths and helper commands differ, as shown in the table above.

### Why does Apache fail with "Address already in use"?

Another web server, often Nginx, is using port 80. Check with `sudo ss -tlnp | grep ':80'` and stop one of them.

### How do I run PHP with Apache?

Install PHP and the Apache module, or PHP-FPM. See [install a LAMP stack](https://help.freakhosting.com/portals/other/how-to-install-a-lamp-stack.md).

### Does .htaccess work?

Yes, when the `<Directory>` block has `AllowOverride All`, as in the example. Without it, Apache ignores `.htaccess` files.

## Related guides

> [card] [VPS and dedicated server guides](https://help.freakhosting.com/portals/other/vps-and-dedicated-server-guides.md)
>
> Every server guide in one place.

> [card] [Install a LAMP stack](https://help.freakhosting.com/portals/other/how-to-install-a-lamp-stack.md)
>
> Apache, MariaDB and PHP.

> [card] [Free SSL with Certbot](https://help.freakhosting.com/portals/other/how-to-get-a-free-ssl-certificate-with-certbot.md)
>
> Add HTTPS to Apache.

> [card] [Install Nginx](https://help.freakhosting.com/portals/other/how-to-install-nginx.md)
>
> The other popular web server.

> [card] [Website not loading](https://help.freakhosting.com/portals/other/how-to-fix-website-not-loading-on-your-vps.md)
>
> Step-by-step checks.

***

> [!NOTE]
>
> **Checked against the official [Ubuntu Server documentation](https://ubuntu.com/server/docs/how-to/web-services/install-apache2/) and [Red Hat Enterprise Linux 9 Apache guide](https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/9/html/deploying_web_servers_and_reverse_proxies/setting-apache-http-server_deploying-web-servers-and-reverse-proxies)** on 4 November 2026; install, virtual host and `configtest` commands tested on Ubuntu 24.04 LTS (Apache 2.4.58). Commands can differ on other distributions or releases.

> [!NOTE]
>
> ### Need Extra Help?
>
> If you encounter any issues, our support team is ready to assist:
>
> * **Live Chat:** Quick assistance via our website.
> * **Support Ticket:** [Open a Ticket](https://freakhosting.com/clientarea/submitticket.php)
> * **Discord:** [Join our Community](https://discord.gg/freakhosting)
> * **Email:** [support@freakhosting.com](mailto:support@freakhosting.com)

> [!TIP]
>
> ### Save on Your Hosting
>
> Ready to upgrade your hosting? Use code **KB20** at checkout for **20% off** your first order!

***

**Last Updated:** November 2026


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.