How to View Effective Apache HTTPD Configuration in cPanel (Including Parsed Directives)


10 views

When managing Apache servers in cPanel environments, configuration directives often get scattered across multiple include files (httpd.conf, vhost includes, .htaccess, etc.). This becomes particularly problematic when:

  • Directives are defined in multiple locations with different values
  • Include statements create complex inheritance chains
  • Server-wide settings conflict with virtual host configurations

For a quick overview of how Apache is parsing your vhost configurations:

# As root or via sudo
apachectl -S

# Sample output:
VirtualHost configuration:
*:80                   is a NameVirtualHost
         default server example.com (/etc/apache2/sites-enabled/000-default.conf:1)
         port 80 namevhost example.com (/etc/apache2/sites-enabled/000-default.conf:1)
                 alias www.example.com
         port 80 namevhost dev.example.com (/etc/apache2/sites-enabled/dev.conf:8)

For a complete parsed configuration including all merged directives:

# Requires Apache 2.2+
apachectl -t -D DUMP_CONFIG > parsed_config.txt

# Check specific directives with grep:
grep -i "MaxClients" parsed_config.txt
grep -n "Timeout" parsed_config.txt

Apache 2.4+ provides module-specific dumping capabilities:

# Dump loaded modules and their configurations
apachectl -M 2>&1 | grep "_module"

# For specific modules (e.g., mod_ssl):
apachectl -t -D DUMP_MODULES -D DUMP_RUN_CFG 2>&1 | grep ssl_module -A20

In cPanel environments, additional locations to check:

# Main cPanel Apache config
/etc/apache2/conf/httpd.conf

# Per-account includes
/usr/local/apache/conf/userdata/

# Global includes
/usr/local/apache/conf/includes/

When KeepAlive settings appear in multiple locations:

# 1. Find all occurrences
find /etc/apache2 /usr/local/apache/conf -type f -name "*.conf" | xargs grep -l "KeepAlive"

# 2. Verify which one is active
apachectl -t -D DUMP_CONFIG | grep -A5 -B5 "KeepAlive"

# 3. Check running server's compiled settings
apachectl -V | grep -i "DEFAULT_KEEPALIVE"

Remember these precedence rules in Apache:

  • Last matching directive wins
  • <Directory> overrides <Location>
  • .htaccess overrides directory configs (if AllowOverride is enabled)
  • VirtualHost settings override global settings

Create a validation script:

#!/bin/bash
CONFIG_DUMP=$(apachectl -t -D DUMP_CONFIG 2>&1)

check_directive() {
    echo "$CONFIG_DUMP" | grep -i "$1"
}

# Example checks
check_directive "Timeout"
check_directive "KeepAlive"
check_directive "MaxRequestWorkers"

When troubleshooting Apache configurations on cPanel servers, it's crucial to understand how directives merge from multiple include files. The effective configuration is determined by:

  • Main httpd.conf file
  • Include directives (loaded in order)
  • .htaccess files (if AllowOverride is enabled)
  • Last-match-wins rule for duplicate directives

The most comprehensive way to view effective settings is using:

apachectl -S
# Or alternatively:
httpd -S

This command outputs:

  • VirtualHost configurations in resolution order
  • Listening IPs and ports
  • Document roots
  • Server names/aliases
  • Loaded modules

For checking specific directive values, use:

apachectl -t -D DUMP_MODULES
apachectl -t -D DUMP_INCLUDES
apachectl -t -D DUMP_RUN_CFG

On cPanel servers, configuration is typically split across:

/etc/apache2/conf.d/
/etc/apache2/conf/httpd.conf
/usr/local/apache/conf/includes/

Use this command to trace include files:

httpd -t -D DUMP_INCLUDES 2>&1 | grep -i "your_directive"

Let's say you need to verify the effective KeepAlive setting:

# First check all locations where it might be defined
grep -r "KeepAlive" /etc/apache2/

# Then verify the active setting
apachectl -S | grep -i "KeepAlive"

# For more details, examine compiled config
httpd -V | grep -i "DEFAULT_KEEPALIVE"

Create a diagnostic script:

#!/bin/bash
echo "=== Effective Settings ==="
apachectl -S 2>&1 | tee apache_status.txt
echo "\n=== Loaded Modules ==="
apachectl -M 2>&1 | tee apache_modules.txt
echo "\n=== Directive Values ==="
for directive in KeepAlive Timeout MaxClients; do
    apachectl -S 2>&1 | grep -i "$directive" | tee -a apache_directives.txt
done