Skip to content

Instantly share code, notes, and snippets.

@skwid138
Last active May 3, 2021 17:30
Show Gist options
  • Save skwid138/f83ebe70bcc2ee78ee2d1f372f908848 to your computer and use it in GitHub Desktop.
Save skwid138/f83ebe70bcc2ee78ee2d1f372f908848 to your computer and use it in GitHub Desktop.

Helpful Composer Commands

Verbose Flag composer update -vvv composer update [package name] -vvv

Update Autoloaded class map

This is helpful if you've changed the file structure. I beleive this also occurs when running composer update

composer self-update

Update Composer Autoloader

This is helpful if class names were changed etc. It does run as part of composer update as well as composer install, but you may not want to do those things

composer dump-autoload

Clear Composer Cache

This is useful for a number of reasons, [reasons here... hehe]

composer clearcache or composer clear-cache

Re Install Packages

If a change is made to the composer.json it might be small, but it likely will change the composer.lock.

rm -rf ./vendor/* && composer install composer install --prefer-source composer update composer update [package name]

Update specific Package(s)

composer update [package name] composer update [package name 1] [package name 2]

Update the lockfile only

If there are changes on the composer.json, but you don't want to update the vendor package version(s)

composer update --lock

Troubleshooting

composer diagnose Potentially helpful when trying to resolve an error


Flags

I beleive these work for both composer update and composer install

  • --prefer-source - Install packages from source when available
  • --prefer-dist - Install packages from dist when available
  • --ignore-platform-reqs - ignore php, hhvm, lib-* and ext-* requirements and force the installation even if the local machine does not fulfill these. See also the platform config option.
  • --dry-run - Simulate the command without actually doing anything.
  • --dev - Install packages listed in require-dev (this is the default behavior).
  • --no-dev - Skip installing packages listed in require-dev. The autoloader generation skips the autoload-dev rules.
  • --no-autoloader - Skips autoloader generation.
  • --no-scripts - Skips execution of scripts defined in composer.json.
  • --no-plugins - Disables plugins.
  • --no-progress - Removes the progress display that can mess with some terminals or scripts which don't handle backspace characters.
  • --optimize-autoloader or -o - Convert PSR-0/4 autoloading to classmap to get a faster autoloader. This is recommended especially for production, but can take a bit of time to run so it is currently not done by default.
  • --lock - Only updates the lock file hash to suppress warning about the lock file being out of date.
  • --with-dependencies - Add also all dependencies of whitelisted packages to the whitelist.
  • --prefer-stable - Prefer stable versions of dependencies.
  • --prefer-lowest - Prefer lowest versions of dependencies. Useful for testing minimal versions of requirements, generally used with --prefer-stable.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment