Declare dependencies
Composer stores direct dependencies in composer.json. A typical requirement might look like:
{
"require": {
"php": "^8.2",
"monolog/monolog": "^3.0"
}
}
The PHP constraint documents the minimum compatible runtime range. Choose package constraints that match the PHP version available in your development and production environments.
Install the locked versions
When a lock file exists, use:
composer install
This installs the versions recorded in composer.lock, helping different environments use the same dependency set.
Update dependencies deliberately
To resolve newer versions allowed by the constraints:
composer update
For a targeted update:
composer update monolog/monolog
Review the lock-file changes and run your tests before deploying.
Inspect dependency health
Useful commands include:
composer show
composer outdated
composer audit
composer audit checks installed packages against known security advisories when advisory data is available.
Production workflow
Use composer install --no-dev --optimize-autoloader for a production deployment when appropriate. Keep the lock file under version control, review updates, and avoid running unrestricted dependency updates directly on a live server.