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, but your PHP Module is not compiled to be threadsafe. You need to recompile PHP. AH00013: Pre-configuration failed

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

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

When you attempt to start an Apache server on Android Termux, specifically on Android 9 Pie, you might encounter a critical error preventing the service from launching. The log output AH00013: Pre-configuration failed is often accompanied by the message: "Apache is running a threaded MPM, but your PHP Module is not compiled to be threadsafe." This error indicates a fundamental mismatch between how Apache handles concurrency and how the PHP interpreter was built.

The core issue lies in the Multi-Processing Module (MPM) selected during Apache's compilation versus the build flags used for PHP. In environments like Termux, Apache defaults to the mpm_winnt or a threaded variant depending on the specific package configuration available, though standard Linux distributions usually default to prefork. However, if your environment explicitly loads a threaded MPM (such as mpm_event or mpm_worker), it expects the child processes handling requests to be threadsafe.

PHP is not inherently threadsafe by default. The standard build of PHP disables threading support to prevent race conditions and memory corruption issues within the Zend Engine. When you load a non-threadsafe PHP module (libphp.so) into an Apache instance running with thread-safe MPMs, Apache attempts to pass thread-local storage (TLS) variables or mutex locks to the PHP interpreter. Because the interpreter lacks the necessary internal locks and TLS support, it crashes immediately upon initialization, triggering the AH00013 failure before any request can be processed.

To resolve this, you must recompile PHP with threading support enabled. This involves passing the specific flag -DTHREADSAFE=ON during the build process. If you are compiling from source in Termux or a similar environment, the ./configure command is critical. You need to ensure that the configuration includes options like:

./configure \
    --with-apxs2=/path/to/apxs \
    --enable-mbstring \
    -DTHREADSAFE=ON

The -DTHREADSAFE=ON flag instructs the PHP core to initialize internal locking mechanisms and thread-local storage pointers. Without this, the module simply cannot function in a threaded context. It is important to note that enabling threading support can introduce overhead. In high-concurrency scenarios, the cost of acquiring locks within the Zend Engine might impact performance compared to a single-process model. However, for development environments or mobile setups where resource constraints often dictate the MPM choice, this trade-off is necessary for stability.

Alternatively, you could modify Apache to use a non-threaded MPM like mpm_prefork. This approach avoids recompiling PHP entirely but limits concurrency handling to a process-per-request model, which consumes more memory on devices with limited RAM, such as the Android 9 Pie device mentioned in the source context. Given that Termux often runs within a containerized or restricted environment, sticking to the default threaded MPM and recompiling PHP is generally the cleaner architectural decision.

Once you have recompiled PHP with thread safety enabled, you must ensure that the new shared object replaces the old one in the Apache modules directory. If your installation uses a specific path like /d/d/c/f/u/e/apache2, verify that the libphp.so file corresponds to the newly built version. After replacing the module and adjusting the Apache configuration to load the correct library, restarting the service should clear the error.

If you are deploying PHP alongside Laravel or other frameworks that rely on specific extensions, ensure those extensions were also compiled with the same threading flags. Mixing a threadsafe core with non-threadsafe modules will result in the same crash. Consistency across all loaded modules is mandatory when operating under a threaded MPM.

Our network