Apache is a powerful and capable open-source web server, designed to provide a balance of flexibility, portability, and performance. Apache optimization is an important task for every system administrator.

You can improve Apache’s performance by customizing the Apache configuration without needing to add additional hardware like RAM, CPU etc.

This post describes various Apache configuration options that can be used to improve Apache performance without adding additional hardware resources to your system.

MaxKeepAliveRequests is the maximum number of requests to serve on a TCP connection. It limits the number of requests allowed per connection. If it is set to 0, unlimited requests will be allowed. You can set it to any value you desire.

Keep this setting to a high value for maximum server performance. The recommended value of MaxKeepAliveRequests is 500.

KeepAliveTimeout defines the number of seconds Apache will wait for the new request from connected clients before closing the connection. (Once the server receives a request, the Timeout directive applies instead.)

By default Keepalive is disabled in CentOS 7. If Keepalive is set to on, it is a good idea to set the KeepAliveTimeout value low.

StartServers: This directive sets the number of child server processes created on startup. It is a good idea to increase this number on a high-load server, so the server is ready to handle a lot of connections.

MinSpareServers: This directive sets the minimum number of idle child server processes. This value will need to be tuned for high-load servers.

MaxSpareServers: This directive sets the maximum number of idle child server processes. When there are more idle child server processes than defined by MaxSpareServers the idle process will be killed.

MaxClients: This directive sets the maximum number of simultaneous requests that Apache will handle. When this limit has been reached, any other connection attempts will be queued.

Number of MaxClients = (Total RAM memory – RAM memory used for other process except Apache process) / (Memory used by a single Apache process)

MaxRequestsPerChild: This directive sets how many requests a child process will handle before terminating. Once the limit has been reached, the child process will die.

Note: If this value is 0, then the process will never die.

AllowOverride

If AllowOverride is set to ‘All’, then Apache will attempt to open a .htaccess file in each directory that it visits.

The biggest reason for Apache web server slowdowns is the time required to perform DNS lookups. Apache will record the full host name of each incoming client connection in its access.log file. Resolving each one eats up a significant chunk of time.

The HostnameLookups option enables DNS lookup so that hostnames can be logged instead of the IP address. By default HostnameLookups is Off in Apache.

You can verify that this is the case by editing the Apache config file: