HOW TO OPTIMIZE APACHE PERFORMANCE ON CENTOS 7

Apache is one of the most popular and powerful web servers. And of course, it is open source. It is also known as httpd server. Apache web servers are designed to provide a balance of portability, flexibility, and high performance. Optimizing Apache plays a crucial role in determining the overall performance of the system. Apache is easy to configure and provides simple performance tuning options, which we will discuss in detail today.

PREREQUISITES

  • A live CentOS 7 server
  • Apache web server installed and running

First, let us walk you through the process of installing Apache, incase you haven’t done it already. To install Apache, use the command – sudo yum install httpd as shown below-

The installation will take some time. After the installation, you will be able to see a message on the console as shown below-

The main configuration file (httpd.conf) can be seen in location /etc/httpd/conf.

The httpd.conf file contains some default parameters. You can also add your own parameters based on your requirements. Let’s now start with some performance optimizations.

KEEP ALIVE TIMEOUT-

KeepAliveTimeout is a parameter that defines the number of seconds before closing a connection. This is the maximum seconds Apache will wait for a new request before closing the connection. By default, this parameter is disabled in CentOS 7. However, it is generally good practice to have a KeepAliveTimeout value.

This parameter can be set to a very low value, between 1 and 5. To make this change you can edit the httpd.conf file at location- /etc/httpd/conf

You can add the following line:
KeepAliveTimeout 5

MAX KEEP-ALIVE REQUESTS-

MaxKeepAliveRequests is the maximum number of requests which can be served on a TCP connection. This will allow you to limit the number of allowed connections and will help in effective utilization of network bandwidth, without causing traffic congestion. This is a numeric value which when set to 0, will allow unlimited requests.

The recommended value here is 500. To add this parameter you will have to edit the httpd.conf file

You can add the following line-
MaxKeepAliveRequests 500

 

KEEP-ALIVE-

KeepAlive is a parameter which determines whether more than one request per connection is allowed or not. This helps in ensuring one client does not consume all of the server’s resources. By default, this parameter is disabled in CentOS 7. If you expect Apache to be getting multiple requests from different IPs at once, then this should be turned ON. This can be edited in the httpd.conf file.

In order to turn on this parameter, you can add the following line-
KeepAlive On

 

CONFIGURE MULTI-PROCESSING MODULE-

One of the reasons for slow performance in Apache can be its inability to deal with load. In such cases, a multi-processing module will help.

mpm_prefork_module is part of CentOS 7 and is enabled by default. To confirm this is running, you can use the command- sudo apachectl -t -D DUMP_MODULES |grep mpm

If mod_deflate is enabled it will display mpm_prefork_module (shared)

For better performance, you can also use Apache MPM prefork module. This can be set in the httpd.conf file.

You can add the following lines in the file-
<IfModule prefork.c>
    StartServers 5
    MinSpareServers 5
    MaxSpareServers 10
    MaxClients 150
    MaxRequestsPerChild 3000
</IfModule>

Once the file is saved, you can restart Apache using command- sudo apachectl restart.

Here is a brief explanation of the mentioned parameters-

  • StartServers – This sets the number of child server processes created at startup. Initially, this can be kept as a small number and can be gradually increased on a high payload server. This helps in ensuring the right utilization of server resources.
  • MinSpareServers – This sets the minimum number of idle child server processes and can be tuned for high payload servers.
  • MaxSpareServers – This sets the maximum number of idle child server processes. In case the number of idle child server processes exceeds this value, then the idle processes are killed.
  • MaxClients – This is the maximum number of simultaneous requests Apache can handle. Once this limit is reached, the connection will be queued.
  • MaxRequestsPerChild – This indicates how many requests a child process will handle before terminating. Once this limit has been reached, the child process will die. If this value is set to 0, then the process will never die.

ALLOW OVER RIDE-

The parameter AllowOverride can be set to ‘All’. However, if this is included within a simple directory tag then it will open an .htaccess file for every directory it visits. So if you have the following configuration-
DocumentRoot /var/www/html/example
<Directory /> 
     AllowOverride All
</Directory>

What will happen is that if you make a request to URL /index.html, then Apache will open an .htaccess file for /, /var/, /var/www/, /var/www/html/, /var/www/html/example

To avoid this waste, you can configure AllowOverride for a specific directory, such as:

DocumentRoot /var/www/html/example
<Directory /var/www/html/example/admin> 
     AllowOverride All
</Directory>

DNS LOOKUPS

Another factor that can slow Apache down is the time required to perform DNS lookups. Apache records the full hostname of each incoming request in the access.log file. Resolving each of these can be time consuming.

This is configured with the parameter- HostnameLookups in the httpd.conf file. This enables DNS lookups so that hostnames can be logged instead of IP address. In Apache, by default, this parameter is turned off. This property is defined in the httpd.conf file as-

HostnameLookups Off

Once you’re done making all of the above changes, restart Apache using the command- sudo apachectl restart

And that’s it! Your Apache web server should now be way more efficient than it was before.

Subscribe Now

10,000 successful online businessmen like to have our content directly delivered to their inbox. Subscribe to our newsletter!

Archive Calendar

Sat Sun Mon Tue Wed Thu Fri
 1234
567891011
12131415161718
19202122232425
262728293031  

Over 20000 Satisfied Customers!

From 24/7 support that acts as your extended team to incredibly fast website performance

Zelt staff were fantastic, I had a concern with a domain and they got back to me very quickly and they helped me to resolve the issue!

author
Technician, Diageo PLC

I'm using Zelt for my portfolio since 2006. The transition was seamless, the support was immediate, and everything works perfectly.

author
Photographer, Allister Freeman

Very easy to understand & use even though I am not very technologically minded. No complications whatsoever & I wouldn't hesitate to recommend it to all.

author
Actor, A&J Artists

Zelt support team have been amazingly responsive and helpful to any of my queries, thank you so much to the Zelt have been amazingly responsive and helpful to any of my queries 👍👍👍

author
Technician, Diageo PLC

Anytime I've had a problem I can't solve, I've found Zelt to be diligent and persistent. They simply won't let an issue go until the client is happy.

author
Doctor, SmartClinics

Zelt support team have been amazingly responsive and helpful to any of my queries, thank you so much to the Zelt have been amazingly responsive and helpful to any of my queries 👍👍👍

author
Freelancer, Fiverr

24/7 World-Class Support

Ran into trouble? Contact our Customer Success team any time via live chat or email.

  • Receive professional WordPress support
  • Our specialists are available round
Get Support