phpreverse-proxyreverse

Why does PHP-FPM need a reverse proxy?


I was reading through the PHP page on Docker Hub and finally got down to the nether-regions where they talk about the different variations of images. When they talk about the FPM variation it says:

In order to use this image variant, some kind of reverse proxy (such as NGINX, Apache, or other tool which speaks the FastCGI protocol) will be required.

Why does PHP-FPM need a reverse proxy? What's different about the PHP-FPM implementation that it cant run on an Apache server? Or, am I completely misunderstanding what FPM is?


Solution

  • Based on a comment from Sammitch which should have been an answer.

    FPM (FastCGI Process Manager) speaks FastCGI, an internal protocol designed for components to use inside a web server; it doesn't speak HTTP directly, so can't communicate directly with a browser.

    Therefore, you need something in the middle that speaks both, e.g. Nginx, Apache, etc. The HTTP request is received by this proxy, and forwarded over FastCGI to the FPM process. The FPM process then executes the PHP code.

    This is in contrast to the older model, where the PHP engine was executed directly inside the process of the web server. Most commonly, this was by loading a module ("mod_php") into the Apache web server. Separating the two processes is generally better for security and stability, and the FastCGI protocol is designed to limit the performance impact of them not directly sharing memory.