Nov 272012
Article Apache

An Apache web server can employ different multiprocessing strategies to benefit from the CPU and RAM resources available at the system where it runs. Among them, the most common ones are the “prefork” and “worker” multiprocessing modules (mpm).

Prefork – prefork is the most common mpm strategy used in WordPress installations. In this mode, the main apache process runs a set of children processes, and distributes to them the client requests received.

Worker – If apache is running with worker mpm enabled, the main process also runs a set of children processes, but each of them is also executing a set of execution threads. In this way the processing power increases, and the amount of RAM required is reduced. Running Apache with worker mpm improves the scalability of the service, that is able to process a higher volume of requests than running an apache server with prefork mpm and the same hardware resources.

But in order to use the worker mode, all the modules used by the server must be thread-safe. A notable exception is the case of the mod_php module used to run PHP scripts under apache. This module is not thread-safe, forcing a typical WordPress installation to configure apache in prefork mpm mode.

However, it is possible to use mod_fcgid (Fast CGI) to run a WordPress site with an apache server executing worker mpm, as explained in this post. The apache server will handle all non-php requests, including requests for static content (css, javascript, images,…). When a request for a php page comes in, apache will pass the request to an external process running the PHP interpreter. In this way, the number of apache processes and threads per process can be configured independently from the number of external PHP processes, optimizing the usage of available resources.

How to check the multiprocessing mode of an apache server

In a server running debian or ubuntu, the name of the apache executable is “apache2”. In other servers, such as CentOS, the name is “httpd”. To list the modules compiled in, this executable can be given the “-l” or “-V” switches:

In the example above, the “prefork.c” module is in the list, and therefore the server is using prefork mpm. Otherwise, the module “worker.c” would be listed.

Using the “-V” switch, we get the output:

How to set up apache and PHP with worker mpm and mod_fcgid

The first step is to disable the mod_php4, mod_php5 apache modules, because these are not thread-safe, and therefore they are not compatible with worker mpm:

Next, we must make sure that we have the following packages installed:

  • apache2
  • apache2-mpm-worker
  • libapache2-mod-fcgid
  • php5-cli
  • php5-cgi

In Debian, the apt-get command is used to install the missing packages. For instance:

When apache2-mpm-worker is installed, apt-get uninstalls apache2-mpm-prefork, and also updates other related packages to their thread-safe versions:

Then, the “actions” and “fcgid” modules are enabled:

Now we create a configuration file “/etc/apache2/conf.d/php.conf” with the following content:

and finally, the web server is restarted:



 Posted by at 11:50 am

 Leave a Reply