Using Composer the Right way
If you are not a PHP developer and have no idea about composer then you can skip this article.
If you are a PHP developer then you must be using Composer for Dependency management then most of the time (just like almost every programmers) you must be doing
composer install or
composer update and then
composer dumpautoload even on the Production Server (I was doing the same mistake).
composer install will install all the packages listed in the composer.json file and it is recommended to skip dev packages on Production Server.
so, here I am listing some useful composer commands which will help you to install only the required packages with proper auto-loading.
- Instead of
composer dumpautoload -oor
composer du -o:
composer dumpautoload -owill take more time that
composer dumpautoloadbut after the command the file autoloading will be faster due to PSR-0/4 autoloading to classmap.
- Instead of
composer install --no-dev --optimize-autoloader: Composer by default installs all the packages from composer.json and
--no-devwill prevent it from doing so.
--optimize-autoloadwill optimize autoloader for after autoloading (as mentioned in point 1) post installation.
composer installrecommendation for build scripts: If you are using a CI system then here is the recommended
composer installcommand for build scripts:
composer install --no-ansi --no-dev --no-interation --no-progress --no-scripts --optimize autoloader, what is does: a. Skip Dev dependencies (
--no-dev) b. Optimize autoloader (
--optimize-autoload) c. Stop installation scripts (might cause issue during build but completely dependent on your business logic)(
--no-scripts) d. It will not print progress and will work without generating o/p or asking for any i/p (
You can read more about composer cli and all the options provided by the composer over here: https://getcomposer.org/doc/03-cli.md
[How to deploy correctly when using Composer's develop / production switch?
Composer has the option to load several dependencies only while being in development, so the tools will not be…stackoverflow.com](https://stackoverflow.com/questions/21721495/how-to-deploy-correctly-when-using-composers-develop-production-switch "stackoverflow.com/questions/21721495/how-to..")
[Command-line interface / Commands - Composer
You've already learned how to use the command-line interface to do some things. This chapter documents all the…getcomposer.org](https://getcomposer.org/doc/03-cli.md "getcomposer.org/doc/03-cli.md")
That’s all folks!!!
Thank you for reading :) :) :)