51

How do I tell if apache is running (or configured to run) as prefork or worker?

1
  • 2
    or more technically 'compiled to run as'
    – Simon
    Nov 24, 2009 at 23:54

10 Answers 10

35

The MPM is configured at compile time. One way to figure it out afterwards is to list compiled in modules. That list will include the chosen MPM. The listing can be accomplished running the apache binary, with the -l flag.

andreas@halleck:~$ apache2 -l
Compiled in modules:
 core.c
 mod_log_config.c
 mod_logio.c
 worker.c
 http_core.c
 mod_so.c
andreas@halleck:~$ 

Here we find the module worker.c, hence I'm running the worker MPM.

3
  • 12
    This answer is wrong. See my answer. Feb 11, 2014 at 19:27
  • 1
    Hm, on Ubuntu I have neither worker nor prefork listed when I do this...
    – mlissner
    Nov 16, 2015 at 23:31
  • 2
    On Ubuntu you can use apache2ctl -M to list active modules. Jan 6, 2016 at 14:22
67

In Ubuntu 14.04

a2query -M

Tells event, prefork, worker

You can change it by adding symbolic links for mpm_<chosen> from mods-available to mods-enabled in /etc/apache2.

Only one is allowed in a time.

5
  • 4
    This needs to be the accepted answer.
    – user245374
    Jan 19, 2016 at 16:03
  • yes, great answer! simple and returns what's needed Feb 9, 2018 at 19:50
  • Worked for me the best, thanks (worked on apache 2.4.... looks like it doesn't work on apache 2.2)
    – dmikam
    Feb 13, 2019 at 8:53
  • The event MPM is, according to Apache's site, "a variant of the worker MPM with the goal of consuming threads only for connections with active processing". Apr 30, 2019 at 12:48
  • command not found
    – Nathan B
    Dec 8, 2021 at 11:41
65

The answers given by Series8217 and Andol are both incorrect.

The question was, how to tell if Apache is running prefork or worker. The advice given by the other answers only tells what the default MPM is (based on compiled-in modules), not if that default or another choice is being used at the present time.

If httpd -V shows prefork, that just means prefork is the compiled-in default MPM. That can be overridden by changing an Apache configuration file setting, as shown in this process:

  1. Edit the configuration file (e.g. /etc/sysconfig/httpd on CentOS / RedHat)
  2. Add or uncomment this line: HTTPD=/usr/sbin/httpd.worker
  3. Restart Apache

Which MPM is actually running can be shown using this process:

  1. Enable Apache mod_info
  2. Query the mod_info url, typically curl localhost/server-info
  3. The "Server Settings" section will show "MPM Name: Worker"
  4. Run httpd -V again -- it will still show prefork, not worker

Bottom line:

  • httpd -V shows the default option, not which option is actually in use

There are answers on many, many web sites saying, use httpd -V to tell if Apache is running prefork or worker. They are all wrong. Try the above procedure to see for yourself.

4
  • FYI, according to httpd.apache.org/docs/trunk/mpm.html the MPM can be a static module on all platforms, or built as a DSO (on Unix). When it is built as a static module, "The server must be rebuilt in order to change the MPM." Is the apache documentation incorrect about the static module MPM being unchangeable except by rebuilding the server? Feb 12, 2014 at 21:34
  • This sounds very much like something distro specific, with a higher level wrapper around?
    – andol
    Mar 7, 2014 at 9:08
  • 2
    On CentOS 6.6 /usr/sbin/httpd, /usr/sbin/httpd.event and /usr/sbin/httpd.worker are all distinct binaries with different MPM configured at compile time (prefork, event and worker respectively). Changing the setting of HTTPD in /etc/sysconfig/httpd just controls which binary is run by the init script. Nov 28, 2014 at 15:59
  • I had to run apache2 -V instead of httpd -V on Ubuntu 16.04 LTS Feb 8, 2018 at 4:00
7

On RedHat and derivates, just launch top or ps aux and look at the httpd process name:

  • httpd means Apache is running as prefork
  • httpd.worker means it is running as worker
1
  • I see apache2 processes
    – Nathan B
    Dec 8, 2021 at 11:41
5

Chris Johnson is correct. Go to httpd.conf => add this line:

<Location /server-info>
SetHandler server-info
</Location>

Restart apache: /etc/init.d/httpd restart. Then access localhost/server-info by your browser and look at MPM Name section.

1
  • Of even nicer, put that between <IfModule info_module> </IfModule>
    – Lexib0y
    Oct 25, 2015 at 23:57
5

One way that I figure it out in Debian like distros, is by running:

apachectl -V | grep -i mpm
1
  • Concrete and good answer. Thanks Jun 25, 2022 at 17:53
4

On RHEL/Fedora/etc, run httpd -V. You will get some output which includes the following:

Server version: Apache/2.2.21 (Unix)
     ...
Architecture:   64-bit
Server MPM:     Prefork
     ...

Here 'Server MPM' is 'Prefork', so my server is running the prefork MPM.

3
  • This answer is wrong. See my answer. Feb 11, 2014 at 19:27
  • @ChrisJohnson, interesting discovery... My understanding was that the MPM could not be changed by configuration, only by compilation. It seems the OP thought the same, since he commented on his question with "or more technically 'compiled to run as'". I'll look into reproducing your answer and once I've confirmed it I'll revoke mine. Feb 12, 2014 at 21:30
  • I confirmed via the apache documentation at httpd.apache.org/docs/trunk/mpm.html that MPMs can be built as DSO modules and dynamically loaded with the LoadModule directive, on "Unix and similar platforms". So the MPM can indeed be changed at load time under certain circumstances (which might be the most common configuration these days..) Feb 12, 2014 at 21:37
3

Here's another method that I expect should be reliable in determine which MPM is in use. Add the following to your httpd.conf:

<IfModule prefork.c>
    Header append X-MPM prefork
</IfModule>
<IfModule worker.c>
    Header append X-MPM worker
</IfModule>

Then check the headers using curl -I localhost | grep X-MPM.

3

on centos (or rhel) you can run this command:

ps -ef | grep httpd

if you see /usr/sbin/httpd.worker running, then it is using the worker MPM. if you see /usr/sbin/httpd running, then it is using prefork

2

The answer from Chris Johnson is right.

After enabling the info module, as documented in the Apache Documentation (http://httpd.apache.org/docs/2.2/mod/mod_info.html), this one liner will give you the MPM you're using:

links -dump http://localhost/server-info/?server | grep "MPM Name"

You must log in to answer this question.