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!

© 2022 42coders All rights reserved.