How to Increase MaxClients and ServerLimit in Apache

If your Apache web server stops responding due to reaching the maximum number of allowed client connections, you may need to increase the MaxClients and ServerLimit variables. These settings control the maximum number of simultaneous connections Apache can handle, and adjusting them can help improve server performance and stability.

Understanding MaxClients and ServerLimit

The MaxClients directive sets the maximum number of simultaneous connections Apache can handle, while ServerLimit defines the upper limit for the MaxClients value. If MaxClients exceeds ServerLimit, Apache will automatically lower MaxClients to match ServerLimit.

Steps to Increase MaxClients and ServerLimit

  1. Locate the Apache Configuration File:
    The configuration file is typically located at:

    /usr/local/apache/conf/httpd.conf
  2. Edit the Configuration File:
    Open the file in a text editor and locate the MaxClients and ServerLimit directives. Increase their values to a higher number, such as:

    ServerLimit 500
    MaxClients 500

    Note: Ensure that MaxClients does not exceed ServerLimit.

  3. Save and Restart Apache:
    Save the changes and restart the Apache service. However, if you’re using Apache 2.x or higher, the changes may not persist after a restart, and the values may reset.

Common Warning Message

After restarting Apache, you may encounter the following warning message:

Code:
WARNING: MaxClients of 500 exceeds ServerLimit value of 256 servers, lowering MaxClients to 256. To increase, please see the ServerLimit directive.

This warning indicates that the MaxClients value exceeds the ServerLimit value, and Apache has automatically adjusted it.

Making Changes Permanent

To ensure the changes persist and are not overwritten during a cPanel update, execute the following commands:

/usr/local/cpanel/bin/apache_conf_distiller –update –main
/usr/local/cpanel/bin/build_apache_conf

These commands will update the Apache configuration and rebuild it, making your changes permanent.

Best Practices

  • Monitor Server Resources: Increasing MaxClients and ServerLimit can consume more server resources (e.g., RAM, CPU). Monitor your server’s performance to ensure it can handle the increased load.
  • Use a Staging Environment: Test the changes in a staging environment before applying them to your production server.
  • Optimize Apache Configuration: Consider other Apache optimizations, such as adjusting KeepAlive settings or enabling caching, to further improve performance.

Final Thoughts

Increasing MaxClients and ServerLimit can help your Apache server handle more simultaneous connections, improving its responsiveness and stability. However, it’s essential to balance these settings with your server’s available resources to avoid overloading the system. By following the steps above, you can make these changes permanent and ensure your server runs smoothly even under heavy traffic.