14

Looking at https://hub.docker.com/_/php I can see reference to php-cli and php-fpm.

Now, I am aware of the concepts of PHP FPM - Fast CGI Process Manager. I'm also aware the PHP can be run in the command line and for php composer and Symfony console.

Does the Docker php-fpm not have PHP CLI tools like php-fpm. Or is php-fpm a superset of php-cli ?

Why would one choose one or the other?

Thank you.

1 Answer 1

17

They are different tools for different purposes:

  • php-cli is the standalone tool for running a PHP scripts in the same way you would run it from the command line: php somescript.php. It seems you can also use it to base other images from.

    This variant contains the PHP CLI tool with default mods. If you need a web server, this is probably not the image you are looking for. It is designed to be used both as a throw away container (mount your source code and start the container to start your app), as well as a base from which to build other images.

  • php-fpm is the FastCGI server implementation of PHP which you would use with a FastCGI compliant web server such as Apache or Nginx.

    This variant contains PHP-FPM, which is a FastCGI implementation for PHP. See the PHP-FPM website for more information about PHP-FPM.

You also have two other variants:

  • php-apache which is just Apache configured with mod_php
  • php-alpine is the smallest possible Docker image based upon Alpine Linux, albeit with some compatibility issues.

You can see all of the Dockerfiles on GitHub and whilst it doesn't appear that php-fpm is based upon php-cli practically they are likely to be very similar and php-fpm is probably a superset of php-cli.

1
  • From this, my understanding would be php-fpm container would be used with a web server (itself in another container). This would occur both in development and production environments. Additionally, for development environments only, an additional separate php-cli container to run php composer in and symfony console in. Commented Oct 21, 2019 at 14:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.