GrepBoard/Manuals
605 manuals ·

Fix Apache: threaded MPM, but PHP module not threadsafe

·Tested on Ubuntu 24.04 · Apache 2.4.58 · PHP 8.3.6 (Docker) · 2026-10·Test scope ↓·5 steps

Apache refuses to start (AH00013) when a threaded MPM is loaded with a non-thread-safe mod_php. Switch back to prefork, or move to event plus PHP-FPM.

output
[Tue Oct 27 01:12:29.295642 2026] [php:crit] [pid 9012:tid 140067354376064] 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

Apache is running a threaded MPM (event or worker) and the loaded mod_php is not built thread-safe (ZTS), so Apache refuses to start. The message says to recompile PHP, but in practice you do one of two things: switch back to mpm_prefork, or drop mod_php and use event with PHP-FPM.

The php.net install page says the same: "Unless PHP was compiled with Zend Thread Safety (--enable-zts), mod_php requires the prefork MPM", most distribution packages are not built with ZTS, and if you need a threaded MPM, "use PHP-FPM with mod_proxy_fcgi instead".

[1] Check the enabled MPM and PHP module. When the config test fails, apache2ctl -M stops with the same error, so list the symlinks directly.

console
# ls /etc/apache2/mods-enabled/ | grep -E 'mpm|php'# php -i | grep -i 'thread safety'
output
mpm_event.confmpm_event.loadphp8.3.confphp8.3.loadThread Safety => disabled

mpm_event and php8.3 together with Thread Safety => disabled (NTS) is exactly the condition for this error.

[2] Work out how it got there. On Ubuntu, installing libapache2-mod-php switches Apache to prefork by itself:

output
Module mpm_event disabled.Enabling module mpm_prefork.apache2_switch_mpm Switch to preforkapache2_invoke: Enable module php8.3

From there, using the tools to turn prefork off and event on is refused at both steps. This is the test running the two commands in a row:

console
# a2dismod -q mpm_prefork; a2enmod mpm_event; echo "exit=$?"
output
ERROR: The following modules depend on mpm_prefork and need to be disabled first: php8.3ERROR: Module mpm_prefork is enabled - cannot proceed due to conflicts. It needs to be disabled first!Considering conflict mpm_worker for mpm_event:Considering conflict mpm_prefork for mpm_event:exit=1

The first line is a2dismod refusing because php8.3 depends on prefork; the rest is a2enmod stopping on the prefork module that is still enabled (the ERROR lines go to stderr, so they print before the Considering lines).

So the error usually appears when someone swapped the symlinks by hand while following tuning advice, or a config management tool or image build script pinned the MPM to event. In the test, removing the prefork links and creating event links by hand produced the error at the top. Swapping in event while leaving prefork in place gives AH00534: apache2: Configuration error: More than one MPM loaded. instead.

[3] To keep using mod_php, go back to prefork. It is the quickest fix with the fewest changes.

console
# a2dismod mpm_event# a2enmod mpm_prefork# apache2ctl configtest# apache2ctl -V | grep 'Server MPM'# systemctl restart apache2
output
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 192.0.2.10. Set the 'ServerName' directive globally to suppress this messageSyntax OKServer MPM:     prefork

AH00558 is only a missing-ServerName warning and unrelated. systemctl restart was not run because the test was in a container.

[4] To keep event, disable mod_php and hand PHP to PHP-FPM. The Ubuntu package php8.3-fpm ships the Apache config for it (conf-available/php8.3-fpm.conf).

console
# apt install php8.3-fpm# a2dismod php8.3 mpm_prefork# a2enmod mpm_event proxy_fcgi setenvif# a2enconf php8.3-fpm# apache2ctl configtest
output
Enabling module mpm_event.Considering dependency proxy for proxy_fcgi:Enabling module proxy.Enabling module proxy_fcgi.Module setenvif already enabledEnabling conf php8.3-fpm.Syntax OK

.php requests go to FPM through SetHandler "proxy:unix:/run/php/php8.3-fpm.sock|fcgi://localhost" in that file. Check that FPM is running with systemctl status php8.3-fpm, then restart Apache.

[5] After the switch, request one PHP file and check that the body is PHP output. Raw source means the handler is not wired up; a 503 or Primary script unknown points at the FPM side — see AH01071 Primary script unknown.

Analyze your Apache log in the browser ↗ — nothing is uploaded.

#apache#php#mpm#php-fpm