Answers: <p>They are different tools for different purposes:</p>
  <ul>
  <li><p><strong>php-cli</strong> is the standalone tool for running a PHP scripts in the same way you would run it from the command line: <code>php somescript.php</code>.  It seems you can also use it to base other images from.</p>
  <blockquote>
  <p>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.</p>
  </blockquote>
  </li>
  <li><p><strong>php-fpm</strong> is the FastCGI server implementation of PHP which you would use with a FastCGI compliant web server such as Apache or Nginx.</p>
  <blockquote>
  <p>This variant contains PHP-FPM, which is a FastCGI implementation for PHP. See the <a href="https://php-fpm.org/" rel="noreferrer">PHP-FPM</a> website for more information about PHP-FPM.</p>
  </blockquote>
  </li>
  </ul>
  <p>You also have two other variants:</p>
  <ul>
  <li><strong>php-apache</strong> which is just Apache configured with <code>mod_php</code></li>
  <li><strong>php-alpine</strong> is the smallest possible Docker image based upon Alpine Linux, albeit with some compatibility issues.</li>
  </ul>
  <p>You can <a href="https://github.com/docker-library/php/tree/master/7.3" rel="noreferrer">see all of the Dockerfiles</a> on GitHub and whilst it doesn't appear that <code>php-fpm</code> is based upon <code>php-cli</code> practically they are likely to be very similar and <code>php-fpm</code> is probably a superset of <code>php-cli</code>.</p>
  
Answers: CC BY-SA 4.0
Answers: 2019-10-21T14:49:28.090Z
Answers: 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.
Answers: therobyouknow
Answers: CC BY-SA 4.0
Answers: 2019-10-21T14:26:51.260Z
Answers: 2019-10-21T14:33:46.327Z
Answers: 2020-06-18T08:28:10.803Z
Answers: Richard Slater
Body: <p>Looking at <a href="https://hub.docker.com/_/php" rel="noreferrer">https://hub.docker.com/_/php</a> I can see reference to <code>php-cli</code> and <code>php-fpm</code>.</p>
  
  <p>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.</p>
  
  <p>Does the Docker <code>php-fpm</code> not have PHP CLI tools like <code>php-fpm</code>. Or is <code>php-fpm</code> a superset of <code>php-cli</code> ?</p>
  
  <p>Why would one choose one or the other?</p>
  
  <p>Thank you.</p>
  
Tags: <docker><php><images>
Title: What is the difference between php-cli and php-fpm, why 2 php variants and why choose one or the other?
UserDisplayName: therobyouknow
ThreadText: # What is the difference between php-cli and php-fpm, why 2 php variants and why choose one or the other?
  
  (Asked by: username_0 on 2019-10-21)
  
  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.
  
  **Tags:** docker, php, images
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2019-10-21. Score: 17 | Accepted answer
  
  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](https://php-fpm.org/) 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](https://github.com/docker-library/php/tree/master/7.3) 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`.
  
  > **Comments:**
  > **username_0**: 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.  
  
  ---
  
  