On this page
- Why is Apache called apache2 on one system and httpd on another?
- How do you install Apache?
- How do you allow web traffic through the firewall?
- How do you create a virtual host?
- How do you manage Apache modules?
- How do you turn on HTTPS?
- Which performance settings matter?
- How do you troubleshoot Apache?
- Questions
Why is Apache called apache2 on one system and httpd on another?
It is the same Apache HTTP Server 2.4, packaged under two naming traditions. The Debian family uses apache2 for the package, service and config directory, and adds helper scripts such as a2ensite and a2enmod. The Red Hat family uses httpd and loads everything from include directories without helper scripts.
- Ubuntu and Debian: package
apache2, config in/etc/apache2/, userwww-data, logs in/var/log/apache2/. - Rocky and Alma: package
httpd, config in/etc/httpd/, userapache, logs in/var/log/httpd/.
Keep this split in mind when you read any instructions; the directives are identical, only paths and tools change.
How do you install Apache?
Update packages, install, then enable the service so it starts after every reboot. On Ubuntu 24.04, 22.04 and Debian 12 or 13:
sudo apt update
sudo apt install -y apache2
sudo systemctl enable --now apache2
apache2 -vOn Rocky Linux 9 and AlmaLinux 9, also install mod_ssl now, since HTTPS needs it later:
sudo dnf install -y httpd mod_ssl
sudo systemctl enable --now httpd
httpd -vBefore you start, make sure you can log in as a sudo user (see first SSH session) and that your domain has A and AAAA records pointing at 198.51.100.24 and 2001:db8:4f2a::24.
How do you allow web traffic through the firewall?
Open HTTP and HTTPS in the OS firewall and keep SSH allowed. The Ubuntu and Debian package ships UFW profiles:
sudo ufw allow OpenSSH
sudo ufw allow 'Apache Full'
sudo ufw enableWith firewalld on Rocky and Alma:
sudo firewall-cmd --permanent --add-service=http --add-service=https
sudo firewall-cmd --reloadTest from your own computer with curl -I http://198.51.100.24/. You should see a Server: Apache header and the default test page status. On Rocky and Alma that page answers with 403 until you add content, which still proves Apache is reachable.
How do you create a virtual host?
Give each domain its own document root and its own virtual host file. Prepare the directory first:
sudo mkdir -p /var/www/example.net/public
sudo chown -R deploy:deploy /var/www/example.net
echo '<h1>Apache serves example.net</h1>' > /var/www/example.net/public/index.htmlWrite the virtual host. On Debian and Ubuntu save it as /etc/apache2/sites-available/example.net.conf; on Rocky and Alma save it as /etc/httpd/conf.d/example.net.conf and replace ${APACHE_LOG_DIR} with /var/log/httpd.
<VirtualHost *:80>
ServerName example.net
ServerAlias www.example.net
DocumentRoot /var/www/example.net/public
<Directory /var/www/example.net/public>
Options -Indexes +FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/example.net-error.log
CustomLog ${APACHE_LOG_DIR}/example.net-access.log combined
</VirtualHost>Enable it on the Debian family and switch off the stock site:
sudo a2ensite example.net.conf
sudo a2dissite 000-default.conf
sudo apache2ctl configtest && sudo systemctl reload apache2On Rocky and Alma, the file is picked up automatically: run sudo restorecon -Rv /var/www/example.net, then sudo apachectl configtest && sudo systemctl reload httpd. Options -Indexes stops Apache from listing folders; directory listing explains that option in more depth.
How do you manage Apache modules?
On Ubuntu and Debian, modules are switched with a2enmod and a2dismod, which create or remove symlinks in mods-enabled. Common ones for a modern site are rewrite, headers, ssl and http2:
sudo a2enmod rewrite headers ssl http2
sudo apache2ctl -M | sort
sudo systemctl restart apache2Rocky and Alma load most modules out of the box through files in /etc/httpd/conf.modules.d/. To disable one, comment its LoadModule line in that directory; to list what is active, run httpd -M.
Pick the multi-processing module carefully. event is the default and the right choice with PHP-FPM. The older prefork is only needed for mod_php, which uses far more memory per connection. The LAMP stack guide shows how to pair Apache with PHP-FPM.
How do you turn on HTTPS?
Certbot with the Apache plugin requests a certificate and writes the TLS virtual host for you.
# Ubuntu and Debian
sudo apt install -y certbot python3-certbot-apache
# Rocky and Alma
sudo dnf install -y epel-release
sudo dnf install -y certbot python3-certbot-apache
sudo certbot --apache -d example.net -d www.example.net
sudo certbot renew --dry-runOn Debian systems the plugin creates example.net-le-ssl.conf and enables it. When it asks, choose the redirect so plain HTTP visitors move to HTTPS. Afterwards, enable HTTP/2 inside the TLS host with Protocols h2 http/1.1 and reload. The Certbot guide covers other challenge types.
Which performance settings matter?
With the event MPM, the useful knobs are the worker limits and keep-alive. A reasonable start for a 2 vCPU, 4 GB server looks like this, saved as /etc/apache2/conf-available/tuning.conf (enable with a2enconf tuning) or /etc/httpd/conf.d/tuning.conf:
<IfModule mpm_event_module>
ServerLimit 8
StartServers 2
ThreadsPerChild 25
MaxRequestWorkers 200
</IfModule>
KeepAlive On
KeepAliveTimeout 5
ServerTokens Prod
ServerSignature OffMaxRequestWorkers must not exceed ServerLimit times ThreadsPerChild. ServerTokens Prod hides version details. Restart Apache after MPM changes, since a reload does not resize the process pool.
How do you troubleshoot Apache?
Run the syntax test first; most failures are typos it reports with a line number. Then check the service and the logs:
sudo apachectl configtest
systemctl status apache2 # or httpd
sudo journalctl -u apache2 -n 50
sudo tail -f /var/log/apache2/example.net-error.log- AH00558 could not reliably determine the server name: harmless; add
ServerName example.netto the main config to silence it. - 403 Forbidden: missing
Require all granted, wrong file permissions, or on Rocky and Alma a wrong SELinux label. - Wrong site shown: the request did not match any
ServerNameand fell back to the first virtual host loaded. - Port in use: check with
sudo ss -ltnp | grep :80.
Updates arrive with normal system upgrades. After an upgrade, run apachectl -v to confirm the version and load the site once.
Plans that fit this guide
Base city prices. Every plan includes a dedicated IPv4 address, IPv6, full root and all 18 images.
Questions about Install and configure Apache
Is apache2 different software from httpd?
No. Both are Apache HTTP Server 2.4. Only the package name, service name, file paths and helper scripts differ between the Debian and Red Hat families.
Should I use .htaccess files?
They are handy for apps such as WordPress that ship rewrite rules. If you control the server, putting the rules in the virtual host and setting AllowOverride None is faster.
How do I enable mod_rewrite?
On Ubuntu and Debian run sudo a2enmod rewrite and restart Apache. On Rocky and Alma it is loaded by default; check with httpd -M | grep rewrite.
Which MPM should I use?
Use event together with PHP-FPM. Switch to prefork only for old setups that still depend on mod_php.
Can Apache sit behind Nginx?
Yes. Move Apache to Listen 127.0.0.1:8080 and let Nginx proxy to it. Install mod_remoteip settings so Apache logs the real visitor address.
More in Web servers and proxies
- Install and configure Nginx
- OpenLiteSpeed web server
- HAProxy load balancer and TLS proxy
- Load balancing with Nginx upstreams
- Nginx as a reverse proxy for an app
- Apache as a reverse proxy
- Compression with gzip and Brotli
- HTTPS and www redirects
- Turn off Apache directory listings
- Nginx Proxy Manager with Docker
- Nginx UI web interface
- Traefik for Docker containers
- Apache Tomcat for Java apps
- Encrypted FTP with vsftpd (FTPS)
- Varnish cache in front of a site