Apache Keeps reverting to mpm_prefork (Apache 2.4.7 / Ubuntu 14.04.2)

apache-2.4httpd.confmpm-prefork

I have had this problem for over a year now whereby each time there is a security update to Ubuntu and I have to reboot the server, Apache 2.4 decides to start using the mpm_prefork worker despite the fact I have mpm_event set as the enabled module in /etc/apache2/mods-enabled.

I went as far as editing the mpm_prefork.conf file in /etc/apache2/mods-available and commenting out where it loads the module but after a reboot this morning apache just would not start at all because it was insisting on starting up using Prefork.

Here is my /etc/apache2/mods-enabled/ directory list

access_compat.load
actions.conf
actions.load
alias.conf
alias.load
auth_basic.load
authn_core.load
authn_file.load
authz_core.load
authz_host.load
authz_user.load
autoindex.conf
autoindex.load
deflate.conf
deflate.load
dir.conf
dir.load
env.load
evasive.conf
evasive.load
expires.load
fastcgi.conf
fastcgi.load
filter.load
headers.load
mime.conf
mime.load
mpm_event.conf
mpm_event.load
negotiation.conf
negotiation.load
pagespeed.conf
pagespeed.load
rewrite.load
setenvif.conf
setenvif.load
socache_shmcb.load
spamhaus.conf
spamhaus.load
ssl.conf
ssl.load
status.conf
status.load

I checked to see if it had been compiled into Apache by running apache2 -l and this was the output

Compiled in modules:
  core.c
  mod_so.c
  mod_watchdog.c
  http_core.c
  mod_log_config.c
  mod_logio.c
  mod_version.c
  mod_unixd.c

And finally the result of a2query -M is

sudo a2query -M
event

But if I reboot right now, Apache is dead on startup because it wants the mpm_prefork module which as I said I have disabled by commenting out in its .conf file to prevent it loading which was not a solution to my problem.

I honestly am stumped as to where Apache 2.4 is just deciding by itself to load the mpm_prefork all the time.

Here is also my apache2.conf file stripped down without the comments

# Global configuration
Mutex file:${APACHE_LOCK_DIR} default
PidFile ${APACHE_PID_FILE}
Timeout 40
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 5
User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}
HostNameLookups Off
ErrorLog ${APACHE_LOG_DIR}/apache-error.log
LogLevel warn
SetEnvIf Remote_Addr "127\.0\.0\.1" loopback
SetEnvIf Remote_Addr "::1" loopback
CustomLog ${APACHE_LOG_DIR}/apache-access.log combined env=!loopback

# Include module configuration:
IncludeOptional mods-enabled/*.load
IncludeOptional mods-enabled/*.conf

# Include list of ports to listen on
Include ports.conf


<Directory />
    Options -Indexes +FollowSymLinks
    AllowOverride None
    Require all granted
</Directory>

<Directory /usr/share>
    AllowOverride None
    Require all granted
</Directory>

<Directory /var/www/>
    Options -Indexes +FollowSymLinks
    AllowOverride None
    Require all granted
</Directory>

<Directory /var/www/html/opcache/>
    Options -Indexes +FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>


AccessFileName .htaccess

<FilesMatch "^\.ht">
    Require all denied
</FilesMatch>

LogFormat "%V %v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %O" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent
LogFormat "%h %l %u %t \"%r\" %>s %O %b %D \"%{Referer}i\" \"%{User-Agent}i\"" custom


IncludeOptional conf-enabled/*.conf

IncludeOptional sites-enabled/*.conf

Best Answer

The problem looks to be that you have these installed as packages:

apache2-mpm-event 2.4.7-1ubuntu4.9 amd64 transitional event MPM package for apache2
apache2-mpm-prefork 2.4.7-1ubuntu4.9 amd64 transitional prefork MPM package for apache2

When you update, you are specifically telling the server to install the prefork version. If you have a proper install of Apache2 on Ubuntu 14.04, which would NOT have specified the MPM type, a dpkg -l | grep apache2 would include:

apache2 2.4.7-1ubuntu4.9 amd64 Apache HTTP Server

but would NOT show the two packages you have listed.

The proper Apache2 installation on Ubuntu 14.04 is simply:

sudo apt-get install apache2

without any specification of MPM. The basic Multi-Processing Modules are core features of Apache 2.4, and are included with the apache2 install.

You then set MPM as follows:

To determine which MPM is currently in use, run apache2ctl -V. You will see a line such as:

 Server MPM:     prefork

Assuming, for example, that you are running "prefork" (as in the above example apache2ctl -V result above) following the install, the switch to "event" is made with the following commands:

 sudo a2dismod mpm_prefork
 sudo a2enmod mpm_event
 sudo service apache2 restart

which will set up the correct symlink.

Once set up this way, under the correct install, updates WILL NOT change your settings.

NOTE: Your "edits" to *.conf files should be taking place in the /etc/apache2/mods-available directory, where they are protected from over writing during updates. The /etc/apache2/mods-enabled directory will just have symlinks back to /etc/apache2/mods-available.