how to optimize apache?

Filed in Centos 7 comments

Apache Default connection Limit

Apache by default is limited to handle not more than 256 requests per second, so you should do  a litle optimization  by installing a module and a few configuration of that module to make apache enable to handle more than 256 requests per second for high traffic servers. The reason of this default limit is that apache to be able to run on every servers even if they are not powerful and has less ram such a 512MB and not using so much resource that may cause server overload and crash.So if your apache hasn’t configured properly on your powerful server, then by reaching its limit on MaxClients , your apache web server  will go down repeatedly that may make you so much surprised.Follow the below solution to optimize your apache web server.At the end please ask your question by leaving a comment and i’ll be  so happy to assist you.

also if you have noticed this error in the server log

[error] server reached MaxClients setting, consider raising the MaxClients setting

then this is the right place for you to raise MaxClients and get rid of this error and have your apache optimized to handle more than 256 or 150 default MaxClients limits requests upto even 200

1-Compiling Apache with Needed extra Module

First you must recompile apache with mpm_perfork and if you have cpanel there is an option to add mod_prefork in the easy apache update so add that.This module has been installed and tested on apache running on Centos Linux server.

2 Edit Confiugration of Apache mpm_prefork Module

After recompiling is complete you should now edit this module configuration.You have two choices, whether to create sepprated configuration file and include it in httpd.conf or edit httpd.conf directly that I myself suggest external configuration.I will train both.

2-1 Create External configration file

nano /etc/httpd/conf/highperformance.conf

if somthing failed due to using the default highperformance.conf then create another file let say highpreformance2.conf ,

nano /usr/local/apache/conf/highpreformance2.conf

2-2 Including configration in httpd.conf

open httpd.conf

nano /usr/local/apache/conf/httpd.conf

the location of httpd.conf may be vary to use

run the following command to find where it is

locate httpd.conf

and add this line that contain inclusion of external config file

Include "/usr/local/apache/conf/highperformance.conf"

or if your config name is “highperformance2.conf” it should be

Include "/usr/local/apache/conf/highperformance2.conf"

It is completely depend on the name of your external config file name.

2-3 Or Editing httpd.conf directly

or you can also directly edit the httpd.conf instead of creation of external file and include it in httpd.conf

nano /usr/local/apache/conf/httpd.conf

2-3 Writing your custom prefork configration

After opening the httpd.conf or seprated configration file edit the prefork directives or if “<IfModule prefork.c>” does not exist add the following completely to it:

ServerLimit 2000
KeepAlive On
KeepAliveTimeout 60
MaxClients 1600
MaxSpareServers 200
MinSpareServers 50

3- Prevent Apache configration from being overwritten

After that you edit apache configration “httpd.conf” directly or included seprated configration then you should run the following command to prevent any changes or overwritten that would be  occure to the config with cpanel:

/usr/local/cpanel/bin/apache_conf_distiller --update

4 Restart Apache for the Changes Take Effect

You are done now but After all modification to apache configration for the changes take effect you need to restart apache webserver
to do so run the following command

service httpd restart

or if you have cpanel installed on your centos server just run the following shell script by just running the command:

/scripts/restartsrv_apache

as my server is powerfull that have 8gig of ram and have a lot of connection I have used the following settings in it that; it doesn’t mean you should have the same settings that I have

click MaxClients to find it out better

I will tell you each of these apache prefork directive in a better detail later on

Please do not hesitate to ask any questions by commenting here regarding any part that is not clear.

I will be so much grateful to answer your questions .

voshka

No related posts.

Posted by voshka   @   4 January 2010 7 comments

Share This Post

RSS Digg Twitter StumbleUpon Delicious Technorati

7 Comments

Comments
Jun 1, 2010
10:13 am
#1 irlogo :

Hello,

who to find mod_prefork in ease apache?

Author Jun 1, 2010
12:31 pm
#2 voshka :

Hi, irlogo

if you mean how to find it and enable it in easy apache
there is a module called mpm_prefork
by sellecting it you will have it compiled with apache build
is that what you mean?

Thanks

Feb 4, 2011
6:01 am
#3 sidh :

my server having 12 gb of ram and 12 core cpu with 12 mb catch

what config do i have to put?

Author Feb 4, 2011
8:54 am
#4 voshka :

Hi

Thats All depends on they way you are going to use your server
ranging from a simple shared hosting with advanced shared hosting with so many websites hosted on it to a server dedicated for a site that has so much traffic and if it has a high load of numbers of downloads

Please let me know what exactly your intention to use of this server has fallen to

THanks

May 9, 2012
6:00 pm
#5 Mr_Parham :

Hi
My server has 4 cores, 16GB of ram. As you can see I own a leech website so there would be a lot of downloading, any recommendation on the settings??

Author May 12, 2012
11:23 pm
#6 voshka :

Please provide me the type of cpu you have to assist you better
Thanks

Trackbacks to this post.
Leave a Comment

Previous Post
«
Next Post
»
CrossBlock designed by DeltaManual.Com  |  In conjunction with Web Hosting   |   Web Hosting   |   Reverse phone