Difference with shinsenter/phpfpm-nginx and shinsenter/php
Closed this issue · 1 comments
Hi..
What is the difference with shinsenter/phpfpm-nginx and shinsenter/php using nginx and php-fpm??
Hello @brnpimentel.
Thank you for asking, however I'm not sure I fully understand your question.
My docker images currently have the following variants:
shinsenter/php:cli
- only includes PHP CLI, for executing PHP files in a terminal environment.shinsenter/php:fpm
- includes PHP CLI and PHP-FPM, mainly used for compiling PHP files for web applications.shinsenter/php:fpm-nginx
- same asshinsenter/php:fpm
, but with Nginx pre-installed as the web server.shinsenter/php:fpm-apache
- same asshinsenter/php:fpm
, but with Apache 2 pre-installed as the web server.shinsenter/php:unit-php
- same asshinsenter/php:cli
, but with Nginx Unit pre-installed as the web server.shinsenter/php:frankenphp
- same asshinsenter/php:cli
, but with FrankenPHP pre-installed as the web server.
⇧
These docker images are suitable for projects that require deployment to a single container (for example instead of using one nginx and one php-fpm containers to run a web application, you can just use oneshinsenter/php:fpm-nginx
container to do the same thing), allowing reduced operating costs. You can also use theshinsenter/php:fpm
image with any other web server container you prefer, this is completely up to you and your project's needs.
If you've been asking about the differences between the combination of [Nginx + built-in PHP] and [Nginx with PHP-FPM], I believe there are many other articles on the Internet that have done benchmarks and provided figures for comparison. I won't cite them here as benchmark data can vary depending on each author's setup, and are meant more for reference.
I think the main differences are:
- Running PHP directly in Nginx uses the native PHP module. All PHP scripts are handled within the Nginx worker processes. This provides less flexibility in scaling and resource allocation.
- PHP-FPM (FastCGI Process Manager) runs PHP scripts independently in a separate process from Nginx. This provides better performance, security, and resource utilization compared to running PHP directly in Nginx.
- With PHP-FPM, PHP processes can be managed and scaled independently from Nginx. You can have multiple PHP-FPM pools with different configurations. This allows more flexibility in allocating resources.
- PHP-FPM communicates with Nginx via FastCGI. This allows them to run on separate servers if needed. PHP scripts are passed from Nginx to PHP-FPM via FastCGI.
- With Nginx + PHP-FPM, it's easier to secure the applications by limiting vulnerabilities from the web server affecting the application. And vice versa.
- Using PHP-FPM provides more monitoring and metrics on the PHP processes and application performance. This helps troubleshoot issues more easily.
Overall, Nginx + PHP-FPM provides a more efficient and flexible architecture for running PHP applications at scale compared to running PHP directly in Nginx. The separation of web server and application processes is a best practice for most production environments.
Best regards