- Category : Server Administration
- Posted on : Feb 15, 2017
- Views : 1,724
- By : Odalis J.
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.
- 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:
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-
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-
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-
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-
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:
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-
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.
- cPanel Question 47
- cPanel Software Management 29
- cPanel Tutorials 13
- Development 29
- Domain 13
- General 19
- Linux Helpline (Easy Guide) 156
- Marketing 47
- MySQL Question 13
- News 2
- PHP Configuration 14
- SEO 4
- SEO 42
- Server Administration 84
- SSL Installation 54
- Tips and Tricks 24
- VPS 3
- Web Hosting 44
- Website Security 22
- WHM questions 13
- WordPress 148
Subscribe Now10,000 successful online businessmen like to have our content directly delivered to their inbox. Subscribe to our newsletter!
Posted on : Sep 17
Posted on : Sep 10
Posted on : Aug 04
Posted on : Apr 01
- server load
- ddos mitigation
- layer 7
- seo vpn
- Hosting Security
- smtp relay
- VPS Hosting
- cheap vpn
- Small Business
- SSD Hosting
- Link Building