Initialize a New Project
composer init
Walks you through creating a new composer.json
file.
Install Dependencies
composer install
Installs all dependencies listed in composer.lock
. If composer.lock
doesn’t exist, it installs from composer.json
and creates composer.lock
.
Require a Package
composer require <vendor/package>
Installs a new package and adds it to composer.json
.
Remove a Package
composer remove <vendor/package>
Uninstalls a package and removes it from composer.json
.
Update All Packages
composer update
Updates all packages to the latest versions allowed by composer.json
and updates composer.lock
.
Update a Specific Package
composer update <vendor/package>
Updates only the specified package.
List Installed Packages
composer show
Shows all installed packages and their versions.
Show Direct Dependencies
composer show --direct
Shows only the packages directly required in composer.json
.
View Detailed Info on a Package
composer show <vendor/package>
Displays detailed information about a specific package.
Find Which Package Depends on Another
composer depends <vendor/package>
Shows which packages depend on a given package.
Generate Autoload Files
composer dump-autoload
Rebuilds the autoload files without installing or updating packages.
Optimize Autoload
composer dump-autoload --optimize
Optimizes autoload files for better performance in production.
composer validate
composer.json
and composer.lock
are valid and properly formatted.Check for Available Package Updates
composer outdated
Lists packages with newer versions available.
Get Package Suggestions
composer suggest
Shows optional packages suggested by installed packages.
View Package Funding Information
composer fund
Displays funding links for installed packages (e.g., GitHub Sponsors).
Clear Composer Cache
composer clear-cache
Clears the Composer cache to free up space or fix issues with cached packages.
Install Without Dev Dependencies
composer install --no-dev
Installs only the production dependencies, skipping any require-dev
packages.
Install With Dev Dependencies (default)
composer install
Installs both production and development dependencies.
phpunit/phpunit
composer require --dev phpunit/phpunit
guzzlehttp/guzzle
composer require guzzlehttp/guzzle
laravel/framework
composer require laravel/framework
symfony/console
composer require symfony/console
nesbot/carbon
composer require nesbot/carbon
monolog/monolog
composer require monolog/monolog
phpmailer/phpmailer
composer require phpmailer/phpmailer
fakerphp/faker
composer require --dev fakerphp/faker
doctrine/orm
composer require doctrine/orm
predis/predis
composer require predis/predis
intervention/image
composer require intervention/image
swiftmailer/swiftmailer
composer require swiftmailer/swiftmailer
respect/validation
composer require respect/validation
twig/twig
composer require twig/twig
symfony/dotenv
.env
file.composer require symfony/dotenv
league/oauth2-client
composer require league/oauth2-client
vlucas/phpdotenv
.env
file.composer require vlucas/phpdotenv
spatie/laravel-permission
composer require spatie/laravel-permission
barryvdh/laravel-debugbar
composer require barryvdh/laravel-debugbar --dev
michelf/php-markdown
composer require michelf/php-markdown