Composer command
Here is the example for Composer command:-
| Command | Note |
| composer show | Show a list of the packages installed with their version number |
| composer show -s | Check the list of root level required packages (with dev). |
| composer show --tree vendor-name/package-name | Show the tree of a required package. |
| composer why [--tree] vendor-name/package-name | Check why a package was installed. |
| composer why-not vendor-name/package-name VERSION.NUMBER | Check why a package version was not installed. |
| composer home vendor-name/package-name | Visit the package’s repository |
| composer outdated | See all outdated package, which package hasn’t the latest version |
| composer update | Updates all outdated |
| composer update vendor-name/package-name | Update specific package |
| composer global update vendor-name/package-name | Update global package |
composer remove vendor-name/package-name Example: composer remove drupal/fontawesome_iconpicker | Remove php package from project |
| composer install | Install packages Note: install command first create a composer.lock if not exists composer.lock file. composer lock file contains composer.json all package with version. then install those packages. |
| composer init | init command create your composer.json schema with some arguments. |
| composer dump-autoload | autoload is the most important command. This command adds class, alias, provider etc inside vendor’s composer folder. |
| COMPOSER_MEMORY_LIMIT=-1 composer [command_here] | If your containers run out of memory (Maximum allowed memory allocation problem) |
| COMPOSER_MEMORY_LIMIT=-1 composer update -vvv | If your composer [command] screen is frozen, and you want to know if it’s working or not, use the following -vvv flag to print out all the debug logs. |
| composer composer clear-cache | To clear all the cached packages |
| composer composer list | View all the list of available commands |
| composer -h, --help | Display help for the given command |
| composer -q, --quiet | Do not output any message |
| composer -V, --version | Display this application version |
| composer --ansi|--no-ansi | Force (or disable --no-ansi) ANSI output |
| composer -n, --no-interaction | |
| composer --profile | Display timing and memory usage information |
| composer --no-plugins | Whether to disable plugins |
| composer --no-scripts | Skips the execution of all scripts defined in composer.json file |
| composer -d, --working-dir=WORKING-DIR | If specified, use the given directory as working directory |
| composer --no-cache | Prevent use of the cache |
| composer -v|vv|vvv, --verbose | Increase the verbosity of messages: 1 for normal output, 2 formore verbose output and 3 for debug |
| composer about | Shows a short information about Composer |
| composer archive | Creates an archive of this composer package |
| composer audit | Checks for security vulnerability advisories for installed packages |
| composer browse | [home] Opens the package's repository URL or homepage in your browser |
| composer bump | Increases the lower limit of your composer.json requirements to the currently installed versions |
| composer check-platform-reqs | Check that platform requirements are satisfied |
| composer clear-cache | |
| composer completion | Dump the shell completion script |
| composer config | Sets config options |
composer create-project Example (for Drupal 10): | Creates new project from a package into given directory This will create a project in 'my_site_name_dir' and automatically executes composer install to download the latest stable version of Drupal and all its dependencies. Your 'my_site_name_dir' will contain files that should be outside of your web root and not accessible by the web server. The web root will be 'my_site_name_dir/web'. |
| composer depends | [why] Shows which packages cause the given package to be installed |
| composer diagnose | Diagnoses the system to identify common errors |
| composer dump-autoload | [dumpautoload] Dumps the autoloader |
| composer exec | Executes a vendored binary/script |
| composer fund | Discover how to help fund the maintenance of your dependencies |
| composer global | Allows running commands in the global composer dir ($COMPOSER_HOME) |
| composer help | Display help for a command |
| composer install | [i] Installs the project dependencies from the composer.lock file if present, or falls back on the composer.json |
| composer licenses | Shows information about licenses of dependencies |
| composer prohibits | [why-not] Shows which packages prevent the given package from being installed |
| composer reinstall | Uninstalls and reinstalls the given package names |
composer require Example: | [r] Adds required packages to your composer.json and installs them |
| composer run-script | [run] Runs the scripts defined in composer.json |
| composer search | Searches for packages |
| composer self-update | [selfupdate] Updates composer.phar to the latest version |
| composer status | Shows a list of locally modified packages |
| composer suggests | Shows package suggestions |
| composer update | [u|upgrade] Updates your dependencies to the latest version according tocomposer.json, and updates the composer.lock file |
| composer validate | Validates a composer.json and composer.lock |
| composer drupal:scaffold | [scaffold] Update the Drupal scaffold files |
Composer command in practice
1) Create Project (Drupal 10)
composer create-project drupal/recommended-project my_site_name_dir
2) Install Module / Thems
Run: composer require drupal/module_name
Example: composer require drupal/token
3) Update Drupal Core
a) Check the list available drupal update: composer outdated "drupal/*"
b) If there is an update, first check / verify whether the project uses drupal/core-recommended or drupal/core.
Check if drupal use core-recommended
Run: composer show drupal/core-recommended
* If drupal/core-recommended is installed, this command returns information about the package.
* If drupal/core-recommended is not installed, this command returns "Package drupal/core-recommended not found".
If you are using drupal/core-recommended:
composer update "drupal/core-*" --with-all-dependencies
If you are not using drupal/core-recommended but instead only drupal/core:
composer update drupal/core --with-dependencies
4) Update to the latest patch version of core
Read more:
https://www.drupal.org/docs/develop/using-composer/manage-dependencies
client = ca-pub-2898279488603899
slot = 9058461004
format = auto