Updated: 28 September 2026 · Applies to: Apache httpd 2.4.58 to 2.4.68 on AlmaLinux and Rocky Linux 9 and 10, RHEL 9 and 10, Ubuntu 24.04 and 26.04, Debian 13
Apache HTTP Server is one of the most widely used web servers. Its configuration is plain text files, and the layout differs between the Red Hat family and Debian or Ubuntu. This guide explains where things are, how to add a website (virtual host), and how to check and apply changes safely.
Install and start
dnf install httpd && systemctl enable --now httpd # AlmaLinux, Rocky Linux, RHEL apt install apache2 # Ubuntu, Debian (starts automatically)
Where the configuration lives
- AlmaLinux, Rocky Linux, RHEL: main file
/etc/httpd/conf/httpd.conf; your own files in/etc/httpd/conf.d/*.conf; modules in/etc/httpd/conf.modules.d/; logs in/var/log/httpd/; servicehttpd. - Ubuntu, Debian: main file
/etc/apache2/apache2.conf; sites in/etc/apache2/sites-available/, switched on witha2ensite; modules witha2enmod; logs in/var/log/apache2/; serviceapache2. - Default website folder on both:
/var/www/html.
Add a website (virtual host)
- Create the folder and a test page:
mkdir -p /var/www/example.com/public echo "It works" > /var/www/example.com/public/index.html
- Create the virtual host:
/etc/httpd/conf.d/example.com.conf(Red Hat family) or/etc/apache2/sites-available/example.com.conf(Ubuntu, Debian):<VirtualHost *:80> ServerName example.com ServerAlias www.example.com DocumentRoot /var/www/example.com/public <Directory /var/www/example.com/public> Options -Indexes +FollowSymLinks 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 Linux and RHEL, replace${APACHE_LOG_DIR}withlogs(which points to/var/log/httpd). - On Ubuntu and Debian, enable the site:
a2ensite example.com - On AlmaLinux, Rocky Linux and RHEL with SELinux, new folders under
/var/wwwget the right label automatically. For folders elsewhere, label them:semanage fcontext -a -t httpd_sys_content_t "/srv/site(/.*)?"andrestorecon -Rv /srv/site. - Check the configuration, then reload:
apachectl configtest systemctl reload httpd # or: systemctl reload apache2
- Open the firewall for HTTP and HTTPS:
firewall-cmd --permanent --add-service=http --add-service=https && firewall-cmd --reload, orufw allow 'Apache Full'.
Key settings to know
ServerName: the host name a virtual host answers to. Set a global one too, to avoid the "Could not reliably determine the server's fully qualified domain name" warning.AllowOverride All: lets.htaccessfiles change settings, which WordPress and many applications need.Noneis faster and safer when you do not need them.Options -Indexes: never list folder contents.ServerTokens ProdandServerSignature Off: hide the version number.
HTTPS
Get a free certificate with Certbot: install certbot and python3-certbot-apache (from EPEL on AlmaLinux and Rocky Linux), then run certbot --apache -d example.com -d www.example.com.
Common problems
- "Syntax error on line ...":
apachectl configtestnames the file and line. - 403 Forbidden: folder permissions, a missing
Require all granted, or an SELinux label (checkausearch -m avc -ts recent). - The default page shows instead of your site: the
ServerNamedoes not match the address you typed, or the site is not enabled.
Official documentation: Apache virtual host documentation and Configuration files.