On Thu 2024/08/01 13:40:01+0200 (CEST), Walt E wrote:
Hello

I have been using apache2 + php for years under debian.
But I heard people says nginx + php has better performance.
Do you have experience on both of setup and share a bit with me?

Thank you.
Walt Evans

Hello,

**by default**, Apache uses mod_php versus Nginx uses php-fpm. A lot of people credit to nginx a better performance, but it should be credited to php-fpm really!

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, impacting about the real PHP performance. The reason is stability and compatibility along with some modules requiring legacy support like mod_php which **only** works under a process-per-request model (prefork) [1].

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 for Apache 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), get rid mod_php module and migrate to php-fpm service + mod_fcgid module + mpm_event.

Then, only then, you may start thinking an apache versus nginx fair battle.

Regards.

[1] https://www.php.net/manual/en/faq.installation.php#faq.installation.apache2

Reply via email to