Skip to content
Log In Sign Up info@muvcloud.com

Install Apache

On Ubuntu and Debian:

sudo apt update
sudo apt install apache2

The service starts right away and is enabled at boot. On AlmaLinux and Rocky Linux the package is called httpd, and you start it yourself:

sudo dnf install httpd
sudo systemctl enable --now httpd

Check the version with apache2ctl -v on Debian and Ubuntu or httpd -v on AlmaLinux and Rocky Linux. All current releases ship Apache 2.4, and both families use the event MPM by default.

Open the Firewall

Web traffic uses port 80 for HTTP and 443 for HTTPS. If ufw is active on Ubuntu or Debian:

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

If ufw is not enabled yet, allow SSH first with sudo ufw allow OpenSSH (or your custom SSH port) before you run sudo ufw enable, or the firewall cuts off your session. On AlmaLinux and Rocky Linux, firewalld is active by default:

sudo firewall-cmd --permanent --add-service=http --add-service=https
sudo firewall-cmd --reload

If your provider has a firewall in front of the server, open the same two ports there.

Check That It Runs

systemctl status apache2     # Debian and Ubuntu
systemctl status httpd       # AlmaLinux and Rocky Linux
curl -I http://localhost

The status should read active (running), and curl should print an HTTP status line. Then open http://203.0.113.10, with your server's IP address, in a browser. Ubuntu and Debian show the Apache default page, a file at /var/www/html/index.html that you can replace. AlmaLinux and Rocky Linux show a test page while /var/www/html has no index file; the package's welcome.conf sends it with a 403 status, which is expected, and it disappears as soon as you add an index file.

Where the Files Are

ItemDebian and UbuntuAlmaLinux and Rocky Linux
Main file/etc/apache2/apache2.conf/etc/httpd/conf/httpd.conf
Sites/etc/apache2/sites-available//etc/httpd/conf.d/
Modules/etc/apache2/mods-available//etc/httpd/conf.modules.d/
Logs/var/log/apache2//var/log/httpd/
Web root/var/www/html/var/www/html
Service userwww-dataapache

Debian and Ubuntu split the configuration into small files and switch them on with symbolic links: a2ensite and a2dissite for sites, a2enmod and a2dismod for modules, a2enconf and a2disconf for extra settings. The ports Apache listens on are in /etc/apache2/ports.conf. AlmaLinux and Rocky Linux have no such tools: Apache reads every file ending in .conf in /etc/httpd/conf.d/, modules are loaded by LoadModule lines in /etc/httpd/conf.modules.d/, and the Listen lines are in httpd.conf.

Test Before Every Reload

After any change, check the syntax first. A valid configuration prints Syntax OK:

sudo apachectl configtest
sudo systemctl reload apache2     # or: sudo systemctl reload httpd

A reload re-reads the configuration while running requests finish, so visitors notice nothing. A restart drops every open connection, and if the new configuration is broken, Apache stays down. The details are in how to start, stop, and restart Apache.

SELinux on AlmaLinux and Rocky Linux

SELinux is enforcing on these systems and should stay that way. Files under /var/www get the right label automatically. If you keep a site elsewhere, for example in /srv/example.com, label it for Apache:

sudo semanage fcontext -a -t httpd_sys_content_t "/srv/example.com(/.*)?"
sudo restorecon -Rv /srv/example.com

Without the label, Apache answers 403 Forbidden even when the file permissions are correct. The semanage command is in the policycoreutils-python-utils package.

Add HTTPS

On AlmaLinux and Rocky Linux, install the TLS module with sudo dnf install mod_ssl. On Debian and Ubuntu it ships with apache2 and is switched on with sudo a2enmod ssl. Then get a certificate as shown in Certbot Apache.

Next Steps

Updated:

Linux VPS with Full Root Access

MUVCloud cloud servers run on KVM with Enterprise NVMe SSD storage and full root access, in Turkey, the Netherlands, and the USA.

Cloud VPS Plans Starting at2.99 $/mo Cheap Linux VPS

No Limits on Service or Support

You are not on your own as your projects grow. Our support engineers are ready 24/7, on several channels, whenever you need them.

Support specialist
  • 100% customer satisfaction goal
  • Our own hardware
  • 24/7 ticket and email support
  • 4 countries with locations