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
2
  • 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
    Commented May 26, 2016 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
    Commented May 26, 2016 at 10:26

2 Answers 2

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.

10
  • 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
    Commented May 26, 2016 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
    Commented May 26, 2016 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
    Commented May 26, 2016 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
    – MitchellK
    Commented May 26, 2016 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
    Commented May 26, 2016 at 15:28
0

I had the same problem since ubuntu 14 LTS and still on Ubuntu 22 LTS.

And i do install apache correctly (with apt install apache2)

And i do disable/enable mod correctly (with a2dismod mpm_prefork & a2enmod mpm_event)

If the problem come back, check how you installed php (for exemple php8.0), did you use libapache2-mod-php8.0 (or apt install php) ? unless you disable the mod it will revert back to prefork : a2dismod php8.0

Also, if you do your update manually, and read the text, you will have a line saying disabling mpm-event then enabling mpm-prefork which hinted me at this module.

If you want to use php and NOT prefork, you have to use php8.0-fpm

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .