The location of Apache's main configuration file (httpd.conf or apache2.conf) varies by operating system and how Apache was installed. This guide covers the most common locations on modern Linux distributions, macOS, and Windows, along with commands to find the file automatically if your setup differs.
Finding the config file automatically (recommended)
The most reliable method on any Linux or macOS system is to ask Apache where its configuration file is:
apache2 -V 2>/dev/null | grep SERVER_CONFIG_FILE || httpd -V 2>/dev/null | grep SERVER_CONFIG_FILE
This prints the config file path directly. Example output:
-D SERVER_CONFIG_FILE="/etc/apache2/apache2.conf"
Alternatively, use find to search for it:
find /etc /usr/local/etc -name "httpd.conf" -o -name "apache2.conf" 2>/dev/null
Common locations by operating system
| OS / Distribution | Config file path |
|---|---|
| Ubuntu 16.04 and later | /etc/apache2/apache2.conf |
| Debian 9 and later | /etc/apache2/apache2.conf |
| CentOS 7 / RHEL 7 | /etc/httpd/conf/httpd.conf |
| AlmaLinux / Rocky Linux / RHEL 8+ | /etc/httpd/conf/httpd.conf |
| Fedora | /etc/httpd/conf/httpd.conf |
| macOS (built-in Apache) | /etc/apache2/httpd.conf |
| macOS (Homebrew Apache) | /usr/local/etc/httpd/httpd.conf (Intel)/opt/homebrew/etc/httpd/httpd.conf (Apple Silicon) |
| XAMPP on Linux | /opt/lampp/etc/httpd.conf |
| XAMPP on macOS | /Applications/XAMPP/etc/httpd.conf |
| XAMPP on Windows | C:\xampp\apache\conf\httpd.conf |
| cPanel servers (WHM) | /etc/apache2/conf/httpd.conf |
Ubuntu and Debian note: On Ubuntu and Debian, Apache uses
apache2.confas the main configuration file rather thanhttpd.conf. An emptyhttpd.conffile may exist at/etc/apache2/httpd.conffor compatibility purposes, it is not the active configuration. The active config isapache2.conf.
Virtual host configuration files
On Ubuntu and Debian, individual site (virtual host) configuration is not typically in apache2.conf directly. Instead, each site has its own configuration file:
| Location | Purpose |
|---|---|
/etc/apache2/sites-available/ |
All available virtual host config files (not necessarily active) |
/etc/apache2/sites-enabled/ |
Symlinks to active virtual host configs. Enable a site with a2ensite sitename.conf |
/etc/apache2/conf-available/ |
Additional configuration snippets available |
/etc/apache2/mods-enabled/ |
Active Apache modules |
On CentOS/AlmaLinux/RHEL, virtual host files are typically stored in:
/etc/httpd/conf.d/
Editing the configuration file
Always take a backup before editing Apache configuration:
cp /etc/apache2/apache2.conf /etc/apache2/apache2.conf.bak
After making changes, test the configuration before restarting Apache to catch any syntax errors:
apache2ctl configtest # Ubuntu/Debian
httpd -t # CentOS/RHEL/AlmaLinux
Then restart Apache to apply the changes:
sudo systemctl restart apache2 # Ubuntu/Debian
sudo systemctl restart httpd # CentOS/RHEL/AlmaLinux