I upgraded to Ubuntu Server 14.04 expecting the default apache installation would use the new event MPM, but instead I find the old memory-eating prefork.

I've successfully set up event MPM in Arch Linux, but I'm failing to do so on Ubuntu. I keep getting:

Apache is running a threaded MPM, but your PHP Module is not compiled to be threadsafe. You need to recompile PHP

I' ve already installed php-fpm, and configured apache2 to use it, but since the config files for apache2 are different on Ubuntu, i'm not quite sure whether i'm doing it on the right place.

Any idea on how to make PHP thread safe so I can use apache2 event-mpm? (without having to manually recompile php, of course)

up vote 33 down vote accepted

To disable event MPM, you can do sudo a2dismod mpm_event and after that to enable prefork, you should do sudo a2enmod mpm_prefork.

Finally restart apache:

sudo service apache2 restart
  • 2
    You need to be there... Not here.. there... on the top of the Answers list. – Karma Aug 13 '16 at 9:47
  • 1
    This should be the accepted answer! Don't forget to restart apache after doing this: sudo service apache2 restart – Reeno Aug 22 '16 at 16:11
  • 4
    How does this answer the question of how to enable MPM, like the OP asked? You're explaining how to do the opposite of what the OP asked for. – Craig Mar 6 '17 at 8:05
  • 2
    @Mehraban, OP asked word for word "How to enable event MPM?", and your answer is "Just disable event MPM". How is this an acceptable answer? – Nicolas Bouliane Oct 1 '17 at 14:08
  • 1
    @Mehraban That's not the question that was asked though, so all the traffic coming here from Google is getting told "the best way to do X is not do to X". If I ask how to make chocolate cookies, I expect a chocolate cookie recipe. – Nicolas Bouliane Oct 2 '17 at 11:02

This worked for me.

First check if you have this package installed:

dpkg -l | grep libapache2-mod-php5

If you have it just remove it:

apt-get remove libapache2-mod-php5

You can install multiple ways for Apache to communicate with PHP in parallel. Maybe you have (still) the old mod_php installed, additionally to fastcgi/php-fpm.

You can see which modules your Apache has loaded at runtime with

apache2ctl -M

If needed, use sudo to get root privileges. If you see php5_module (shared) among the modules your Apache is currently using, the old mod_php is still installed and blocks you from using mpm_worker or mpm_event.

  • 5
    Can't run that to get mods if the server is not starting, try sudo a2dismod then hit the tab character twice to see a list if mods that can be disabled. If you see php5 diable it. – pferrel Mar 19 '15 at 16:41

Look for the following in the Load Modules sections of your apache configuration file :

LoadModule mpm_event_module modules/mod_mpm_event.so

And replace it with the following module :

LoadModule mpm_prefork_module modules/mod_mpm_prefork.so
  • NO, don't do this! Apache is build modular, so you don't have to change any LoadModule-Lines into your configs. Only do a2dismod mpm_prefork && a2enmod mpm_event. Then restart your apache, and you're done. – suther Oct 10 '17 at 10:26

For me following fully work on debian:

  1. Disable prefork, enable event: a2dismod mpm_prefork && a2enmod mpm_event
  2. remove mod-php5: aptitude remove libapache2-mod-php5
  3. Be aware that you have each php_ Option in your VHost encapsulate by <IfModule mod_php5.c></IfModule>, otherwise apache won't restart
  4. do service apache2 restart

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.