Skip to main content

Composer command

Here is the example for Composer command:-

CommandNote
composer showShow a list of the packages installed with their version number
composer show -sCheck the list of root level required packages (with dev).
composer show --tree vendor-name/package-nameShow the tree of a required package.
composer why [--tree] vendor-name/package-nameCheck why a package was installed.
composer why-not vendor-name/package-name VERSION.NUMBERCheck why a package version was not installed.
composer home vendor-name/package-nameVisit the package’s repository
composer outdatedSee all outdated package, which package hasn’t the latest version
composer updateUpdates all outdated
composer update vendor-name/package-nameUpdate specific package
composer global update vendor-name/package-nameUpdate global package

composer remove vendor-name/package-name

Example: composer remove drupal/fontawesome_iconpicker

Remove php package from project
composer installInstall 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 initinit command create your composer.json schema with some arguments.
composer dump-autoloadautoload 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 -vvvIf 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-cacheTo clear all the cached packages
composer composer listView all the list of available commands
composer -h, --helpDisplay help for the given command
composer -q, --quietDo not output any message
composer -V, --versionDisplay this application version
composer --ansi|--no-ansiForce (or disable --no-ansi) ANSI output
composer -n, --no-interaction 
composer --profileDisplay timing and memory usage information
composer --no-pluginsWhether to disable plugins
composer --no-scriptsSkips the execution of all scripts defined in composer.json file
composer -d, --working-dir=WORKING-DIRIf specified, use the given directory as working directory
composer --no-cachePrevent use of the cache
composer -v|vv|vvv, --verboseIncrease the verbosity of messages: 1 for normal output, 2 formore verbose output and 3 for debug
composer aboutShows a short information about Composer
composer archiveCreates an archive of this composer package
composer auditChecks for security vulnerability advisories for installed packages
composer browse[home] Opens the package's repository URL or homepage in your browser
composer bumpIncreases the lower limit of your composer.json requirements to the currently installed versions
composer check-platform-reqsCheck that platform requirements are satisfied
composer clear-cache 
composer completionDump the shell completion script
composer configSets config options

composer create-project

Example (for Drupal 10): 
composer create-project drupal/recommended-project my_site_name_dir

 

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 diagnoseDiagnoses the system to identify common errors
composer dump-autoload[dumpautoload] Dumps the autoloader
composer execExecutes a vendored binary/script
composer fundDiscover how to help fund the maintenance of your dependencies
composer globalAllows running commands in the global composer dir ($COMPOSER_HOME)
composer helpDisplay 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 licensesShows information about licenses of dependencies
composer prohibits[why-not] Shows which packages prevent the given package from being installed
composer reinstallUninstalls and reinstalls the given package names

composer require

Example:
composer require drupal/token

[r] Adds required packages to your composer.json and installs them
composer run-script[run] Runs the scripts defined in composer.json
composer searchSearches for packages
composer self-update[selfupdate] Updates composer.phar to the latest version
composer statusShows a list of locally modified packages
composer suggestsShows package suggestions
composer update[u|upgrade] Updates your dependencies to the latest version according tocomposer.json, and updates the composer.lock file
composer validateValidates 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
 

 

Google AdSense
client = ca-pub-2898279488603899
slot = 9058461004
format = auto