Skip to main content
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.

Before you start

  • Connect with SSH 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

1

Install the package

Apache starts and is enabled at boot automatically.
2

Check the service

Look for active (running).

How to open the firewall for Apache

On Ubuntu the profile sudo ufw allow 'Apache Full' opens both ports.
If your firewall is not active yet, allow SSH before you enable it. See set up ufw or set up firewalld.

Where are the Apache files?

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

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.
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)

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

Test and reload

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.

How to check it worked

configtest should print:
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):
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), 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.

Does .htaccess work?

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

VPS and dedicated server guides

Every server guide in one place.

Install a LAMP stack

Apache, MariaDB and PHP.

Free SSL with Certbot

Add HTTPS to Apache.

Install Nginx

The other popular web server.

Website not loading

Step-by-step checks.

Checked against the official Ubuntu Server documentation and Red Hat Enterprise Linux 9 Apache guide 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.

Need Extra Help?

If you encounter any issues, our support team is ready to assist:

Save on Your Hosting

Ready to upgrade your hosting? Use code KB20 at checkout for 20% off your first order!

Last Updated: November 2026