Select Page

Speed up your apache server running PHP

Speed up your apache server running PHP

Since I am facing performance problem due to the load of visitors and a badly configured server, I decide today to document my findings in this new series of articles.

As soon as PHP run as FastCGI and no more inside an Apache module (mod_php4.so is not multi threaded), You should be able to switch the default MPM setting of Apache from MPM prefork to MPM worker.

So, what’s the difference between prefork and worker?

Quoting from the Apache MPM Prefork page: http://httpd.apache.org/docs/2.0/mod/prefork.html
MPM Prefork implements a non-threaded, pre-forking web server that handles requests in a manner similar to Apache 1.3.

And for the Apache MPM Worker says: http://httpd.apache.org/docs/2.0/mod/worker.html
MPM Worker implements a hybrid multi-process multi-threaded server. By using threads to serve requests, it is able to serve a large number of requests with less system resources than a process-based server.

Server: Strato (www.strato.de)
Operating system: SuSE / openSuSE
Requirements: root access and basic Unix knowledge

1Edit the file  
# vi /etc/sysconfig/apache2

and change the key:

APACHE_MPM=" "

to

APACHE_MPM="worker"

2You can now tune also  default parameters in file /etc/apache2/server-tuning.conf
Here are my settings, these are still the default setting of Apache

vi /etc/apache2/server-tuning.conf

# worker MPM

<IfModule worker.c>
    ServerLimit 16
    # initial number of server processes to start
    StartServers         2
    # minimum number of worker threads which are kept spare
    MinSpareThreads     25
    # maximum number of worker threads which are kept spare
    MaxSpareThreads     75
    # maximum number of simultaneous client connections
    MaxClients       150
    # constant number of worker threads in each server process
    ThreadsPerChild     25
    # maximum number of requests a server process serves
    MaxRequestsPerChild  6000
</IfModule>

3start
# apache2-reconfigure-mpm
this recreate the file  /etc/apache2/sysconfig.d/loadmodule.conf
and restart apache automatically. Test Your site to ensure everything still work as expected.

About The Author

Cédric Walter

I worked with various Insurances companies across Switzerland on online applications handling billion premium volumes. I love to continuously spark my creativity in many different and challenging open-source projects fueled by my great passion for innovation and blockchain technology.In my technical role as a senior software engineer and Blockchain consultant, I help to define and implement innovative solutions in the scope of both blockchain and traditional products, solutions, and services. I can support the full spectrum of software development activities, starting from analyzing ideas and business cases and up to the production deployment of the solutions.I'm the Founder and CEO of Disruptr GmbH.

Categories