10 Tips for PHP Composer

Max Hutschenreiter -


1. Add the composer.lock and the composer.json to Git.
composer install
Composer install will install all the packages you have defined in your composer.lock file.
composer update
Composer update will fetch the newest possible version defined in your composer.json. That means the versions of the packages can change based on your rules. If you put in a * for the version it could install a new version with breaking changes.
The only good place to run a composer update ist your local Environment. But Tipp 2 will help you a little with updating dependencies.

2. Only update what you want
composer update 42coders/document-templates
This would only update the 42coders/document-templates Package and its dependencies. It will not touch any other Package.

3. Use composer command line to get new packages
This one is clear for most people I think.
composer require 42coders/document-templates
This will actually do the following things
– Add the Package in the latest version to the composer.json
– Run a composer update 42coders/document-templates to add it to the composer.lock

4. Finding outdated packages
composer outdated -D
This will search for all packages you are using and list the ones which have new versions available. The -D parameter will only list the packages defined in your composer.json.
Like this as an example.

5. Keep Composer up to date
composer self-update
Will check the currently installed version of Composer and update it if a newer one is available.

6. Rewrite your autoloading files
Sometimes it happens that you get an error some class is not available. But in your code, you see the class …
There is a chance the class isn’t just added to your autoloading files
composer dump-autoload

7. Something is not working
one of the first things you can do if something is not behaving as you expect.
composer diagnose
The output will give you some valuable information. For example, I should read Tipp 5 again 🙂

8. Remove a Package
To safely remove a Package use
composer remove vendor/packagename

9. Find new packages on

10. Contribute to Composer
There are multiple ways how you can contribute to Composer
– Sponsor a Developer who is working on Composer
– Use it’s for hosting private packages
– Work directly on fixing some issues

Tags: PHP · open-source · Composer

Want products news and updates?

Sign up for our newsletter to stay up to date.

We care about the protection of your data. Read our Privacy Policy.

Impressions from our Team

  • Happy birthday 🎁🎈🎂 Filip - #

  • Another day another #mandarinacakeshop 🎂 😀 - #

  • Happy Birthday Ognjen! And marry Christmas to all other 🎄#notacakeshop - #

  • #Office #Garden - #

  • #workhard - #

  • #belgrade #skyline - #

  • #happybirthday Phil :) - #

  • #happybirthday Stefan 🥂 - #

  • #happybirthday Lidija 🍾 - #

  • Say hi 👋 to our newest team member ☕️ - #

  • #bithday #cake 😻 - #

  • #stayathome #homeoffice #42coders - #

  • #stayathome #homeoffice #42coders #starwars :) - #

  • #stayathome #homeoffice #42coders - #

  • We had a really nice time with #laracononline #laravel - #

  • Happy Birthday 🎂 Miloš - #

  • Happy Birthday 🎂Nikola - #

  • #42coders #christmas #dinner what a nice evening :) - #

  • Happy Birthday 🎂 Ognjen - #

  • Wish you all a merry Christmas 🎄🎁 - #

See more!

© 2024 42coders All rights reserved.