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
Asked Answered
L

5

11

How to fix this error in Termux?

Android 9 pie

u0_a197@localhost

/d/d/c/f/u/e/apache2> apachectl start

[Mon Feb 24 10:44:37.594174 2020] [php7:crit] [pid 27013:tid 508989617480] 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 u0_a197@localhost /d/d/c/f/u/e/apache2>

Lenka answered 24/2, 2020 at 5:26 Comment(0)
W
11

disable mpm_worker and enable module mpm_prefork ex: edit file httpd.conf : LoadModule mpm_prefork_module libexec/apache2/mod_mpm_prefork.so #LoadModule mpm_worker_module libexec/apache2/mod_mpm_worker.so

Watchcase answered 23/7, 2020 at 5:59 Comment(2)
In my case, there is no mpm_prefork_module reference in httpd.confChubb
Question is to enable mpm_event and not to run with preforkMedallist
B
6

If you are using Ubuntu/Debian systems, you can use a2enmod and a2dismod to enable or disable an apache2 module

To disable mpm_worker:

sudo a2dismod mpm_worker

To enable mpm_prefork:

sudo a2enmod mpm_prefork

(Don't forget to restart your server)

sudo systemctl restart apache2

or

sudo service apache2 restart
Broads answered 21/8, 2022 at 18:56 Comment(0)
M
2

Make sure mod_php is not installed.

sudo yum remove mod_php -y

It is the oldest and slowest possible configuration. It was suitable for version 2.2 and older, and requires the use of the prefork mpm.

You can check if you're server is using mod_php by looking in output of phpinfo()

mod_php used

Correct/multi-threaded configuration will show Fast CGI:

FPM/FastCGI used

Medallist answered 14/1, 2023 at 15:10 Comment(0)
M
2

In my case I am using arch linux and I get the same error, for me the following works:

sudo nvim /etc/httpd/conf/httpd.conf
    #LoadModule mpm_event_module modules/mod_mpm_event.so
    LoadModule mpm_prefork_module modules/mod_mpm_prefork.so

    LoadModule php_module modules/libphp.so
    AddHandler php-script .php

    Include conf/extra/php_module.conf

sudo systemctl restart httpd

https://wiki.archlinux.org/title/Apache_HTTP_Server#Extensions

Manolo answered 10/6, 2023 at 10:58 Comment(0)
B
0

The main question was solved by the accepted answer, but no one has answered why prefork does work and worker/event do not.

Apache has three types of multi-processing modules (MPM) to handle incoming requests: prefork (legacy, <2.4), worker (newer, >=2.4) and event (newest, >=2.4).

  • Prefork implements a non-threaded, pre-forking web server
  • Worker implements a hybrid multi-threaded multi-process web server
  • Event is a variant of worker implementation consuming threads only for connections with active processing

Most Linux distributions configure prefork module by default. The reason is stability and compatibility. And also, because some legacy modules like mod_php only works under a process-per-request model.

If you need mod_php in your Apache instance, then you cannot benefit from using a threaded multi-processing model (worker or event).

You can find some performance tests between prefork, worker and event modules doing a quick search, getting better performance both worker and event modules versus prefork module.

In order to get PHP under a threaded multi-processing model (worker or event) and serve pages quicker than just using mod_php module (with only-compatible prefork model), you must migrate your actual configuration from mod_php module to php-fpm service + mod_fcgid module + mpm_event.

An answer with a detailed step-by-step guide to configure php-fpm service + mod_fcgid module + mpm_event module exceeds the purpose of the question IMHO, but it is well documented in the recommended readings.

Finally, I would like to mention why mod_php will never support a threaded multi-processing model:

Why shouldn't I use Apache2 with a threaded MPM in a production environment?

PHP is glue. It is the glue used to build cool web applications by sticking dozens of 3rd-party libraries together and making it all appear as one coherent entity through an intuitive and easy to learn language interface. The flexibility and power of PHP relies on the stability and robustness of the underlying platform. It needs a working OS, a working web server and working 3rd-party libraries to glue together. When any of these stop working PHP needs ways to identify the problems and fix them quickly. When you make the underlying framework more complex by not having completely separate execution threads, completely separate memory segments and a strong sandbox for each request to play in, further weaknesses are introduced into PHP's system.

If you want to use a threaded MPM, look at a FastCGI configuration where PHP is running in its own memory space.

Extracted from: https://www.php.net/manual/en/faq.installation.php#faq.installation.apache2

Recommended readings:

Bullington answered 9/7 at 8:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.