Skip to content

Basic Apache Configuration on Linux (Virtual Hosts, Files and Logs)

Updated 3 min read

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/; service httpd.
  • Ubuntu, Debian: main file /etc/apache2/apache2.conf; sites in /etc/apache2/sites-available/, switched on with a2ensite; modules with a2enmod; logs in /var/log/apache2/; service apache2.
  • Default website folder on both: /var/www/html.

Add a website (virtual host)

  1. Create the folder and a test page:
    mkdir -p /var/www/example.com/public
    echo "It works" > /var/www/example.com/public/index.html
  2. 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} with logs (which points to /var/log/httpd).
  3. On Ubuntu and Debian, enable the site: a2ensite example.com
  4. On AlmaLinux, Rocky Linux and RHEL with SELinux, new folders under /var/www get the right label automatically. For folders elsewhere, label them: semanage fcontext -a -t httpd_sys_content_t "/srv/site(/.*)?" and restorecon -Rv /srv/site.
  5. Check the configuration, then reload:
    apachectl configtest
    systemctl reload httpd        # or: systemctl reload apache2
  6. Open the firewall for HTTP and HTTPS: firewall-cmd --permanent --add-service=http --add-service=https && firewall-cmd --reload, or ufw 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 .htaccess files change settings, which WordPress and many applications need. None is faster and safer when you do not need them.
  • Options -Indexes: never list folder contents.
  • ServerTokens Prod and ServerSignature 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 configtest names the file and line.
  • 403 Forbidden: folder permissions, a missing Require all granted, or an SELinux label (check ausearch -m avc -ts recent).
  • The default page shows instead of your site: the ServerName does not match the address you typed, or the site is not enabled.

Official documentation: Apache virtual host documentation and Configuration files.

Related services

KVM VPS hosting

NVMe SSD and full root access, with Free Basic Managed Support.

Managed cPanel VPS

cPanel included; we handle updates, security and monitoring.

Server management

on-demand administration, hardening, migrations and monitoring.

Was this answer helpful?

Still stuck? Open a ticket