0

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
MitchellK
  • 149
  • 8
  • which mpm packages do you have installed? `dpkg -l | grep mpm` for installed and `aptitude search apache.*mpm` to see options. As far as I know, it only lets you even install one at a time (but my web server is still 12.04). – Peter May 26 '16 at 10:04
  • Hi Peter, thanks for the reply .... dpkg -l | grep mpm gave the following output `ii apache2-mpm-event 2.4.7-1ubuntu4.9 amd64 transitional event MPM package for apache2` and `ii apache2-mpm-prefork 2.4.7-1ubuntu4.9 amd64 transitional prefork MPM package for apache2'` ... so I guess it does indeed have two installed but chooses by itself to default to prefork – MitchellK May 26 '16 at 10:26

1 Answers1

1

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.

Colt
  • 2,029
  • 6
  • 21
  • 27
  • Hi Colt, thanks very much for the reply. My apache was installed as part of the Ubuntu setup and all I ever did was install mpm_event and the set that as my chosen mpm. This probably explains why there are 2 mpm's showing. I have done: `sudo a2dismod mpm_prefork sudo a2enmod mpm_event sudo service apache2 restart` so many times and when it so chooses it just switches back to using prefork. As I said normally after some system or security updates. – MitchellK May 26 '16 at 15:05
  • apache2ctl -V gives: `Server version: Apache/2.4.7 (Ubuntu) Server built: Jan 14 2016 17:45:23 Server's Module Magic Number: 20120211:27 Server loaded: APR 1.5.1-dev, APR-UTIL 1.5.3 Compiled using: APR 1.5.1-dev, APR-UTIL 1.5.3 Architecture: 64-bit Server MPM: event threaded: yes (fixed thread count) forked: yes (variable process count)` – MitchellK May 26 '16 at 15:10
  • Sorry to ask as I am new here but Is there any way I can reply on comments and correctly format my post? It's all messed up what I posted above in the last 2 comments. – MitchellK May 26 '16 at 15:14
  • Also to answer your **note:** yes I only make changes in the conf files in the /etc/apache2/mods-available folder. Now next step do I uninstall / purge mpm_prefork as per this web page? [link](https://www.howtoinstall.co/en/ubuntu/trusty/apache2-mpm-prefork?action=remove) – MitchellK May 26 '16 at 15:19
  • Be careful, **`purge` will get rid of your `conf` files and probably also your web sites** if they are associated with the removed package. If you have a backup of all of this, and are able, you can however get rid of all of the `apache` install and start over with a good install. There is clearly something seriously wrong with your setup. An update should never change your configuration. **IN ANY CASE, backup your system/files before doing any of these!** – Colt May 26 '16 at 15:28
  • Thanks Colt, I have good backups but will take a fresh one before doing anything that might cause trouble. It's still strange because I have done no fiddling other than installing mpm_event myself quite early on, server is as stable as anything just this switching of mpm's from time to time that annoys me. I will report back tomorrow, need to tackle this one with a clear head. Thanks for your input. – MitchellK May 26 '16 at 16:33
  • Okay. Just to make sure I am being clear - if you had a proper Ubuntu intstall of `apche2` as above, _no_ additional install was needed to switch to `mpm_event`. Just the 3-line configuration change (also above) and then, of course, optimizing for `event`. To be sure, I made this exact switch some time ago on `Apache 2.4.7` running under `Ubuntu 14.04`. – Colt May 26 '16 at 19:24
  • Thanks Colt, I think I may have inadvertantly installed it following someone's guide or tutorial (you know what bad advice is out there). It seems now since yesterday after doing a2enmod and a2dismod again it has stuck. I will keep an eye on it and report back. Thanks for your input. – MitchellK May 27 '16 at 16:41
  • @MitchellK - is the problem solved? – Colt May 31 '16 at 13:00
  • yes it does actually appear to be solved now. There has been 3 sets of security updates over the past week and a couple of reboots I have done manually just to make sure Apache starts up and each time it seems to be starting up perfectly running mpm_event .... so for now I think this is resolved. _I think re-running **a2dismod mpm_prefork and a2enmod mpm_event** again finally made it stick properly_. Thanks for your help. – MitchellK Jun 02 '16 at 07:12