If you notice persistent problems loading your pages, slow performance, service outages, or any problems related to the Web service, it would be advisable to review your Apache configuration.
The configuration may not fully suit everyone's needs, but it serves as a reference point, as it has been tested on numerous occasions and in many situations, delivering optimal results.
Backing up the Apache configuration
The first thing you need to do is back up the Apache configuration.
The Apache configuration file can usually be found at /etc/apache2/apache2.conf but, depending on the distribution, it may be in other locations, such as /etc/httpd/conf/httpd.conf. To create a backup, run:
# cp /etc/apache2/apache2.conf /etc/apache2/apache2.conf.backupOr, if using httpd:
# cp /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.backupEditing the different values
Once you have made the backup, edit the different values using your preferred editing tool (vi, vim, nano,…). For example:
# vi /etc/apache2/apache2.confFor our proposed optimized configuration, you will need to modify the following values to match those shown below:
Timeout 20
KeepAlive On
MaxKeepAliveRequests 64
KeepAliveTimeout 3
HostnameLookups OffNext, locate the Prefork module section (since this is the one normally used) and set the values as follows:
If you do not know which MPM your Apache is running under, whether prefork or worker, you can check by following the steps in our article Check whether Apache is running under Prefork or Worker
<IfModule mpm_prefork_module>
StartServers 2
MinSpareServers 2
MaxSpareServers 5
ServerLimit 200
MaxClients 200
MaxRequestsPerChild 4000
</IfModule>In newer versions of Apache2.4+, MaxClients has been replaced by MaxRequestWorkers, so you will need to use this parameter instead of MaxClients if your Apache version requires it. Both parameters serve the same purpose: defining the maximum number of requests the server can handle simultaneously. For example:
<IfModule mpm_prefork_module>
StartServers 2
MinSpareServers 2
MaxSpareServers 5
ServerLimit 200
MaxRequestWorkers 200
MaxRequestsPerChild 4000
</IfModule>Once you have made the changes, save the file and restart the service to apply them:
# /etc/init.d/apache2 restartOr:
# /etc/init.d/httpd restartIf problems with Apache persist after making these changes, you can check the Apache error log and look for errors related to MaxClient or MaxWorker:
# grep -i maxclient /var/log/apache2/error_log*Or:
# grep -i maxclient /var/log/httpd/error_log*If the command returns any error messages related to process or connection limits, you will need to adjust the MaxClients or MaxRequestWorkers parameter settings again, increasing their values according to your needs and the resources available on the server.
For more detailed information about these parameters and other settings related to Apache MPMs, see the official documentation:
- Apache 2.0: http://httpd.apache.org/docs-2.0/mod/mpm_common.html
- Apache 2.4: https://httpd.apache.org/docs/current/es/mod/mpm_common.html
Sources: Apache documentation, MaxClients documentation