I am new to ubuntu and would appreciate help overcoming a block setting up LAMP with software versions in this post's title (current I believe as of 11/2016). The problem seems to be an inability to configure Apache 2 with php7 mods.

I am using default packages installed using "tasksel install lamp-server", but the downloaded Apache2 package did not seem to install as configured for php7 mods. For example, the files "php7.0conf" and "php7.0load" were not copied into the folder "etc/apache2/mods-enabled". Using "libapache2-mod-php7.0" also does not seem to enable php7.0 mods. The only instruction I have found to enable php7.0 mods is "a2enmodphp7.0," which does copy the php7 "conf" and "load" files into Apache2's "mods-enabled" folder, but then Apache2 fails to restart with the following error:

"Apache is running a threaded MPM, but your PHP Module is not compiled to be threadsafe. You need to recompile PHP. AH00013: Pre-configuration failed
httpd.service: control process exited, code=exited status=1

I get the same result downloading Apache2 individually (using "apt-get install apache2") followed by "apt-get libapache2-mod-php7.0" and "a2enmodphp7.0".

My research shows this to be a known incompatibility between Apache2 and php7. A wiki on Apache says that Apache runs a threaded MPM while PHP7 is not compiled to be threadsafe. It suggests a workaround using manual changes to Apache configuration files. See Section 4.3 of https://wiki.archlinux.org/index.php/LAMP#PHP.

Before I start tinkering under the hood, I would like to ask the community whether there is a more preferred solution? My trust in the people who put together the default packages leads me to hope they built in something that stitches them together.

1 Answer 1


There are multiple ways to connect PHP to Apache. Those are called server APIs or SAPIs. To use the Apache module mod_php is one such SAPI. But some PHP modules (for example the MySQL module) can't handle working with multiple threads yet, they're not threadsafe. mod_php is a relatively tight coupling between Apache and PHP, so you can't use a threading MPM and not threadsafe PHP modules at the same time.

You've got two options: The first option is to switch to a non-threading MPM, being prefork. That would probably come with a performance penalty.

The second option is, switch to a SAPI that isn't as tightly coupled, like fcgi or PHP-FPM. These basically run as their own daemons, so the Apache MPM doesn't have to care if any modules in, say, the PHP-FPM daemon are thread-safe or not. But to set those up you need to do more than just install a package with apt, so there's a learning curve.

  • Thank you. The solution for me was switching to Apache's prefork MPM using the following commands: sudo a2dismod mpm_event followed by sudo a2enmod mpm_prefork. For the record, the following thread also has helpful information about this error and the FPM and CGI SAPIs: askubuntu.com/questions/760787/… Some other threads suggest that running libapache2-mod-php7.0 should accomplish the switch to Apache's prefork MPM module. It didn't work for me, but the manual commands above appear to be successful.
    – stuart_h
    Nov 29, 2016 at 2:31
  • @stuart_h Good to hear you solved your problem. If you think the answer was helpful, you can mark it as accepted :) Nov 29, 2016 at 10:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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