Some useful composer options we are use for production Docker setup in Laravel apps

Composer logo

As a part of our Docker production setup of Laravel web application we are using the following composer install with some options described below:

  • –optimize-autoloader or -o: This flag tells Composer to optimize the autoloader for better performance. Autoloading is a mechanism in PHP that automatically loads classes when they are needed. Optimizing the autoloader can make your application load faster by reducing the number of file operations required to load classes.
  • –no-dev: This flag tells Composer not to install the development dependencies specified in the `composer.json` file. Development dependencies typically include things like testing libraries, code analysis tools, and other packages that are not needed in a production environment.
  • –prefer-dist: This flag tells Composer to prefer installing package distributions (i.e., ZIP or TAR archives) over the source code from version control repositories. Using distributions can be faster and more efficient because it avoids the need to compile or build the packages from source.

So, when you run

composer install --optimize-autoloader --no-dev

, you are installing the project’s production dependencies while optimizing the autoloading process for better performance and excluding any development-specific dependencies. This is commonly used when preparing a PHP project for deployment to a production server.

We hope this information will help you to prepare your Laravel application for production environment.

The full list of all possible options you could check at composer documentation page.