Apache | Apache Installation | Initial Settings for the Configuration File (http.conf)
Apache is configured in the http.conf file. After installing Apache, you need to update the configuration file to match the installation directory and the port number you use. This page explains the initial settings to perform immediately after installing Apache.
Change the installation directory
The Apache configuration file, http.conf, is located in “/Apache24/conf/” under the installation directory.
On macOS, it is located at /etc/apache2/httpd.conf.
Before editing, make a copy of the http.conf file and keep it as a backup, just in case. If you think this is unnecessary, you can skip it.
Now edit the http.conf file. Since http.conf is a text file, you can open it in a text editor. For example, Windows Notepad can also edit it.
First, search for “ServerRoot” in the file. You will find a section like the following.
#
# ServerRoot: The top of the directory tree under which the server's
# configuration, error, and log files are kept.
#
# Do not add a slash at the end of the directory path. If you point
# ServerRoot at a non-local disk, be sure to specify a local disk on the
# Mutex directive, if file-based mutexes are used. If you wish to share the
# same ServerRoot for multiple httpd daemons, you will need to change at
# least PidFile.
#
Define SRVROOT "c:/Apache24"
ServerRoot "${SRVROOT}"
Set ServerRoot to the directory of the Apache server. Change the default “c:/Apache24” value to the directory where Apache is actually installed. More specifically, the installed directory is set in the SRVROOT variable, and ServerRoot uses that SRVROOT variable. In this article, it was changed as follows.
Define SRVROOT "C:/apache/Apache24"
ServerRoot "${SRVROOT}"
The SRVROOT variable set above is also used in other configuration sections, so the same directory is applied there as well.
#
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
#
DocumentRoot "${SRVROOT}/htdocs"
<Directory "${SRVROOT}/htdocs">
...omitted...
</Directory>
<IfModule alias_module>
...omitted...
#
# ScriptAlias: This controls which directories contain server scripts.
# ScriptAliases are essentially the same as Aliases, except that
# documents in the target directory are treated as applications and
# run by the server when requested rather than as documents sent to the
# client. The same rules about trailing "/" apply to ScriptAlias
# directives as to Alias.
#
ScriptAlias /cgi-bin/ "${SRVROOT}/cgi-bin/"
</IfModule>
#
# "${SRVROOT}/cgi-bin" should be changed to whatever your ScriptAliased
# CGI directory exists, if you have that configured.
#
<Directory "${SRVROOT}/cgi-bin">
AllowOverride None
Options None
Require all granted
</Directory>
Configure the port number
Next, check the port number setting. Search for “Listen” in the file.
#
# Listen: Allows you to bind Apache to specific IP addresses and/or
# ports, instead of the default. See also the <VirtualHost>
# directive.
#
# Change this to Listen on specific IP addresses as shown below to
# prevent Apache from glomming onto all bound IP addresses.
#
#Listen 12.34.56.78:80
Listen 80
Listen specifies which port number and IP address Apache listens on. Communication between a web server and a browser generally uses port 80, so port 80 is also set in the default configuration. Usually you do not need to change it, but if multiple web servers run on the same server computer, change this setting so the port numbers do not conflict.
Configure ServerName
The last setting is ServerName. Search for “ServerName” in the configuration file.
#
# ServerName gives the name and port that the server uses to identify itself.
# This can often be determined automatically, but we recommend you specify
# it explicitly to prevent problems during startup.
#
# If your host doesn't have a registered DNS name, enter its IP address here.
#
#ServerName www.example.com:80
ServerName sets the host name and port number that identify the server itself. In the initial configuration it is commented out. To set it, specify a host name and port number such as “www.example.com:80”. If you omit the port number, the default port number for server requests, 80, is used.
In this article, Apache is installed in a local environment, so the “#” before ServerName was removed and the setting was changed as follows.
#
# ServerName gives the name and port that the server uses to identify itself.
# This can often be determined automatically, but we recommend you specify
# it explicitly to prevent problems during startup.
#
# If your host doesn't have a registered DNS name, enter its IP address here.
#
ServerName localhost:80
When you finish editing the configuration file, save it.