CentrioHost Blog

Stories and News from IT Industry, Reviews & Tips | Technology Blog


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

SatSunMonTueWedThuFri
 123456
78910111213
14151617181920
21222324252627
28293031 

Over 20000 Satisfied Customers!

  • web hosting reviewer
    Valerie Quinn
    CTO, Acteon Group

    Centriohost 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! ~ . . . Read more

  • Joomla hosting reviewer
    Collin Bryan
    Photographer, Allister Freeman

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

  • dedicated server reviewer
    Harry Collett
    Actor, A&J Artists

    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. ~ . . . Read more

  • vps web hosting reviewer
    Porfirio Santos
    Technician, Diageo PLC

    Centrio support team have been amazingly responsive and helpful to any of my queries, thank you so much to the Centriohost have been amazingly responsive and helpful to any of my queries 👍👍👍 ~ . . . Read more

  • wordpress hosting plans reviewer
    Catherine Auer
    Doctor, SmartClinics

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

  • reseller hosting reviewer
    Effectivo Social
    Freelancer, Fiverr

    Recommend their shared hosting for all my SME web design clients. Their cloud or VME offerings are too great to deal with. Pricing is perfect and suitable for all users (͠≖ ͜ʖ͠≖) 👌 ~ . . . Read more

Top