WordPress, PHP, web servers setup options: A recap of available paths

So many paths, there are in today’s world for setting up server for WordPress. Here I try to provide a quick summary for understanding the different options available with regard to PHP and web servers.

Summary

There are two options for running PHP on web servers: PHP’s CGI SAPI or running it as a module for the web server.

Running PHP as CGI means that the server calls the PHP executable every time a request is made, requiring a lot of overhead. However FastCGI runs as a server and allows resources to be reused. This option is available for both Apache and Nginx.

As a module, PHP sits inside your web server. This is a lot faster as there is less overhead for each request.4 This option is only available for Apache.

mod_php

mod_php is an Apache module which allows Apache to interpret PHP files. The PHP interpreter is kind of “embedded” inside the Apache process: there is no external PHP process meaning Apache and PHP can communicate better4.

CGI

Common Gateway Interface (CGI) is an interface specification that enables web servers to execute an external program (like PHP), typically to process user requests3

FastCGI

A binary protocol for interfacing interactive programs with a web server. A variation on the earlier Common Gateway Interface (CGI)1.

PHP FPM

PHP FastCGI Processing Manager (FPM) is an alternative PHP FastCGI implementation with additional features for heavy-loaded sites2. PHP FPM runs as a standalone server and Apache connects to it using FastCGI module like mod_fcgid, mod_fastcgi, mod_proxy_fcgi. Performance is comparable to mod_php

Apache MPM

MPM or Multi Mrocessing Modules are different ways the Apache server handles HTTP requests7.

mpm_prefork (default)

Prefork is compatible with everything (thread safe). It uses multiple child processes and each process serves one request at a time.

It is not very scalable as concurrent requests are made to wait until a server process is free. Uses a lot of RAM for scaling up.

mpm_worker

Threading is used. Child processes spin of child threads. Uses less RAM as threads are used. Better for concurrency. Threads are attached to connections, not requests — a keep alive connection will keep hold of a connection until it is closed.

mpm_event

Available as of Apache 2.4, mpm_event is similar to mpm_worker but uses a dedicated thread to deal with keep-alive connections.

Sources

  1. https://en.wikipedia.org/wiki/FastCGI
  2. https://www.php.net/manual/en/install.fpm.php
  3. https://en.wikipedia.org/wiki/Common_Gateway_Interface
  4. https://stackoverflow.com/questions/2712825/what-is-mod-php
  5. https://serverfault.com/questions/645755/differences-and-dis-advanages-between-fast-cgi-cgi-mod-php-suphp-php-fpm
  6. https://stackoverflow.com/questions/13883646/apache-prefork-vs-worker-mpm
  7. https://serverfault.com/questions/383526/how-do-i-select-which-apache-mpm-to-use/383634#383634

Leave a comment