close x

Howto tune Apache2 and PHP

Well…I needed to improve the performance of my Apache server in Amazon EC2 for our PHP app, so that’s what I did…I’m sure there are a lot of ways to do better and more things than I post here…but…it works for me hehe:

First of all we need to install eAccelerator, this is for PHP:

apt-get install php5-dev
tar -xvjf eaccelerator-
cd eaccelerator-
./configure –enable-eaccelerator=shared

make install
Now We edit /etc/php5/apache2/php.ini , and add the following at the end of file:

zend_extension = “/usr/lib/php5/20090626+lfs/”

eaccelerator.shm_size = “64″

eaccelerator.cache_dir = “/var/cache/eaccelerator”

eaccelerator.enable = “1″ eaccelerator.optimizer = “1″

eaccelerator.check_mtime = “1″

eaccelerator.debug = “0″

eaccelerator.filter = “”

eaccelerator.shm_max = “0″

eaccelerator.shm_ttl = “0″

eaccelerator.shm_prune_period = “0″

eaccelerator.shm_only = “0″

eaccelerator.compress = “1″

eaccelerator.compress_level = “9″

eaccelerator.allowed_admin_path = “/var/www/eaccelerator”

and set the “memory_limit”=32M (this is in my case, I hope php process don’t weight more than this).

In this case I’m going to use an instances in EC2 that have more than one CPU, so I’m going to use mpm-worker in Apache2, for doing this working with php5…let’s do this:

apt-get install apache2-mpm-worker libapache2-mod-fcgid
a2enmod fcgid
aptitude install php5-cgi php5-cli
And add the following lines in the directory section on virtualhost conf file of the app:

AddHandler fcgid-script .php

FCGIWrapper /usr/lib/cgi-bin/php5 .php

Options +ExecCGI

Ok, we are finishing…we just need adjust some parameters in the mpm-worker. Some sites says that you need to know how many memory there are free, and how many memory weights a phpn process…I really dont care, cause I’m goingto use autoscale…so when the server gets around 80% of load I bring it up another one, butthe parameters that I tested are the following:

ServerLimit 512

Timeout 20

KeepAlive On

MaxKeepAliveRequests 1000

KeepAliveTimeout 2

StartServers 10

MinSpareThreads 50

MaxSpareThreads 150

ThreadLimit 256

ThreadsPerChild 64

MaxClients 512

MaxRequestsPerChild 0


Cloud Computing0 comments

Leave a Reply