Reader Stacks

What Is httpd.conf and the Apache Virtual Host Config File?

httpd.conf holds Apache's global server settings, while individual virtual host files define how each specific domain or subdomain on that same server is actually handled.

httpd.conf is Apache's main, global configuration file — but on most real-world setups hosting multiple sites, the actual per-domain behavior lives in separate virtual host files, not in httpd.conf directly.

Where httpd.conf typically lives

# Debian/Ubuntu
/etc/apache2/apache2.conf

# RHEL/CentOS/AlmaLinux
/etc/httpd/conf/httpd.conf

The exact filename and location differ by Linux distribution and Apache packaging — Debian-based systems split configuration across multiple files under /etc/apache2/, while RHEL-based systems keep more of it centralized in a single httpd.conf.

What lives in httpd.conf itself

ServerRoot "/etc/apache2"
Listen 80
User www-data
Group www-data
ServerAdmin admin@example.com
Timeout 60
KeepAlive On

These are genuinely global, server-wide settings — the port Apache listens on, the system user it runs as, connection timeout behavior — that apply across every site the server hosts, regardless of domain.

Where individual domains are actually configured: virtual hosts

# /etc/apache2/sites-available/example.com.conf

    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot /var/www/example.com/public
    ErrorLog ${APACHE_LOG_DIR}/example.com-error.log
    CustomLog ${APACHE_LOG_DIR}/example.com-access.log combined

Each domain or subdomain hosted on the same physical server gets its own virtual host block, defining its document root, server name, and logging separately — this is what allows one Apache installation to serve many completely independent websites.

Enabling a virtual host on Debian/Ubuntu

a2ensite example.com.conf
systemctl reload apache2

a2ensite symlinks the config from sites-available into sites-enabled — the directory Apache actually reads on startup — and reloading (rather than a full restart) applies the change without dropping active connections.

A typical Laravel virtual host, including the crucial DocumentRoot detail


    ServerName example.com
    DocumentRoot /var/www/example.com/public
    
        AllowOverride All
        Require all granted
    

Pointing DocumentRoot specifically at the public subdirectory (not the Laravel project root) is essential for security — the project root contains .env, application code, and other files that must never be directly web-accessible, and this specific one-line difference is one of the more common Laravel deployment misconfigurations.

Why AllowOverride All matters for Laravel specifically

AllowOverride All permits Apache to read and apply a project's own .htaccess file — Laravel's default .htaccess in the public directory is what handles routing every request through index.php, so without this directive enabled, the framework's own URL rewriting rules are silently ignored.

Testing a configuration before reloading

apachectl configtest
# or
apache2ctl configtest

Running a config test before reloading catches a syntax error in either httpd.conf or a virtual host file before it takes effect — reloading with an actual syntax error present can bring down the entire web server across every hosted domain, not just the one being edited.