Where is the Apache configuration in CentOS?

Reading Time: 2 minutes

Apache Main Configuration Files

On a CentOS server, the package manager used to install the Apache web server (such as rpm, yum, or dnf) will typically default to placing the main Apache configuration file in of one of the following locations on the server: /etc/apache2/httpd.conf /etc/apache2/apache2.conf /etc/httpd/httpd.conf /etc/httpd/conf/httpd.conf If you have access to the server via command line, you can confirm the exact location that Apache is loading its configuration file from by running the command apachectl -V or httpd -V (if using an older version of Apache) Either command displays Apache’s version and build parameters: [root@host ~]# apachectl -V Server version: Apache/2.4.39 (cPanel) Server built: May 30 2019 20:13:52 Server's Module Magic Number: 20120211:84 Server loaded: APR 1.7.0, APR-UTIL 1.6.1 Compiled using: APR 1.7.0, APR-UTIL 1.6.1 Architecture: 64-bit Server MPM: event threaded: yes (fixed thread count) forked: yes (variable process count) Server compiled with.... -D APR_HAS_SENDFILE -D APR_HAS_MMAP -D APR_HAVE_IPV6 (IPv4-mapped addresses disabled) -D APR_USE_PROC_PTHREAD_SERIALIZE -D APR_USE_PTHREAD_SERIALIZE -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT -D APR_HAS_OTHER_CHILD -D AP_HAVE_RELIABLE_PIPED_LOGS -D DYNAMIC_MODULE_LIMIT=256 -D HTTPD_ROOT="/etc/apache2" -D SUEXEC_BIN="/usr/sbin/suexec" -D DEFAULT_PIDLOG="/var/run/apache2/httpd.pid" -D DEFAULT_SCOREBOARD="logs/apache_runtime_status" -D DEFAULT_ERRORLOG="logs/error_log" -D AP_TYPES_CONFIG_FILE="conf/mime.types" -D SERVER_CONFIG_FILE="conf/httpd.conf" The HTTPD_ROOT= line will display the root directory for Apache’s installation, and the SERVER_CONFIG_FILE= line will show you the Apache configuration file’s path relative to the root directory of Apache’s installation. To illustrate this using the example output above, the HTTPD_ROOT= line shows us the root directory of Apache is the following: /etc/apache2/ The Apache configuration file’s relative path, listed as SERVER_CONFIG_FILE=”conf/httpd.conf“, is within the Apache installation’s root directory, making the full path to the Apache configuration file: /etc/apache2/conf/httpd.conf

Include Files

In addition to the main Apache configuration file discussed above, Apache settings can also be placed in the Apache Include files. The Include files are additional configuration files that Apache will read if instructed to in the main configuration file. The following are examples of how these Include files are referenced in the main configuration file: Include "/etc/apache2/conf.d/includes/post_virtualhost_global.conf" Include "/etc/apache2/conf.d/*.conf" The first line instructs Apache to read additional configurations from a specific file /etc/apache2/conf.d/includes/post_virtualhost_global.conf. The second line instructs Apache to read additional configurations from any files within the folder /etc/apache2/conf.d/ that have .conf at the end of their filename, as the * is a wildcard character. For example, a file named ‘php.conf’ within the /etc/apache2/conf.d/ would be considered an Include file by Apache, and its configurations would be loaded. You can get a full list of the configuration files Apache currently has loaded, including the main configuration file and any Include files, by running the following command: apachectl -t -D DUMP_INCLUDES

Accessing Apache Configurations in Control Panels

If the CentOS server has a control panel for server management installed, such as cPanel/WHM or Plesk, its interface will provide you with a graphical menu for editing this Apache configuration file. For more information on navigating each control panel, you can refer to our guides Getting Started With Plesk and Getting Started With cPanel/WHM.
Refer a friend and get hosting credit!