Using Composer the Right way

Search for a command to run...

No comments yet. Be the first to comment.
Image Generated using Midjourney I recently published this article, where I am talking about some MidJourney tricks and tips after which I got some messages saying what I Midjourney. I know my bad, I did not talk about Midjourney a lot in that articl...

Most of these tricks work with BlueWillow, Stable Diffusion, and many other models. Image generated using BlueWillow Midjourney is all over the rage right now, people are going crazy over it and trying different prompts to create beautiful artwork bu...

Photo by Towfiqu barbhuiya on Unsplash This is part 3 of the Managing your Finances article series, if you have not read part 1 and part 2, then I would recommend you to read those before starting with this article. You have started the journey and y...

Photo by micheile henderson on Unsplash This is part 2 of the Managing your Finances article series, if you have not read part 1, then you can read it here, after which you can resume this article. If you are sorted with your current financial situat...

Photo by Mathieu Stern on Unsplash Before starting the journey of Financial Freedom or even improving our finances, we should be prepared by assessing our current financial situation to avoid bumps during our journey. Think of this preparation as col...

Composer
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).
By default 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.
composer dumpautoload use composer dumpautoload -o or composer du -o : composer dumpautoload -o will take more time that composer dumpautoload but after the command the file autoloading will be faster due to PSR-0/4 autoloading to classmap.composer install use composer install --no-dev --optimize-autoloader: Composer by default installs all the packages from composer.json and --no-dev will prevent it from doing so. --optimize-autoload will optimize autoloader for after autoloading (as mentioned in point 1) post installation.composer install recommendation for build scripts: If you are using a CI system then here is the recommended composer install command 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 ( --no-progress --no-interaction and --no-ansi )You can read more about composer cli and all the options provided by the composer over here: https://getcomposer.org/doc/03-cli.md
References:
[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 "https://stackoverflow.com/questions/21721495/how-to-deploy-correctly-when-using-composers-develop-production-switch")
[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 "https://getcomposer.org/doc/03-cli.md")
That’s all folks!!!
Thank you for reading :) :) :)