composer
Manage PHP dependencies
TLDR
Interactively create a composer.json file
Add a package as a dependency for this project, adding an entry to composer.json
Install all the dependencies in this project's composer.json and create composer.lock
Uninstall a package from this project, removing it as a dependency from composer.json and composer.lock
Update all the dependencies in this project's composer.json and note new versions in composer.lock file
Update only composer.lock after updating composer.json manually
Learn more about why a dependency can't be installed
Update composer to its latest version
SYNOPSIS
composer [options] [command] [arguments]
PARAMETERS
--help (-h)
Displays help information.
--quiet (-q)
Do not output any message.
--verbose (-v|-vv|-vvv)
Increase verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug.
--version (-V)
Display this application version.
--ansi
Force ANSI output.
--no-ansi
Disable ANSI output.
--no-interaction (-n)
Do not ask any interactive question.
--profile
Display timing and memory usage information.
--working-dir (-d)
If specified, use the given directory as working directory.
--no-plugins
Whether to disable plugins.
--no-cache
Disables the cache.
--optimize-autoloader (-o)
Convert PSR-0/4 autoloading to classmap to get faster autoloader.
--classmap-authoritative (-a)
Autoload classes from the classmap only. Implicitly enables `--optimize-autoloader`.
--apcu-autoloader
Use APCu to cache found/not-found classes.
--ignore-platform-reqs
Ignore platform requirements (php, ext-*, etc.).
--ignore-platform-reqs-dev
Ignore platform requirements in require-dev (php, ext-*, etc.).
--prefer-stable
Prefer stable versions.
--prefer-lowest
Prefer lowest versions.
--only-root-dependencies
Ignore root package dependencies.
--no-scripts
Skips the execution of all scripts defined in composer.json file.
DESCRIPTION
Composer is a dependency management tool for PHP. It allows you to declare the libraries your project depends on and it will manage (install/update) them for you. Composer deals with "packages" (libraries) but it manages them on a per-project basis, installing them in a directory (e.g. 'vendor') inside your project. By default, Composer installs packages from Packagist, which is the main Composer package repository. It is highly customizable allowing you to define your own repositories.
It simplifies the process of including external libraries and ensuring you have the correct versions. By defining dependencies in a `composer.json` file, Composer handles fetching, installing, and updating these dependencies, freeing developers from manually managing library versions and potential conflicts.
CAVEATS
Composer relies on having PHP installed and configured correctly on your system. It requires internet access to download packages from remote repositories (like Packagist).
COMPOSER.JSON
The `composer.json` file is central to Composer's operation. It specifies project metadata (name, description, authors), dependencies (`require` and `require-dev`), autoloading rules, scripts, and other configurations.
VENDOR DIRECTORY
By default Composer installs all dependencies in a `vendor` directory. The autoloader generated by Composer allows easy access to these dependencies without needing to manually `require` each file.
UPDATING DEPENDENCIES
The `composer update` command updates your dependencies to the latest versions allowed by the version constraints specified in `composer.json` and updates the `composer.lock` file. `composer install` installs the versions specified in `composer.lock` or, if it does not exist, resolves and installs dependencies specified in the `composer.json`.
HISTORY
Composer was created by Nils Adermann and Jordi Boggiano and first released on March 1, 2012. It was inspired by other dependency management tools like Bundler (Ruby) and npm (Node.js). Composer quickly gained popularity within the PHP community, becoming the de facto standard for managing dependencies in PHP projects. Its use has contributed to better code organization, reusability, and collaboration within the ecosystem.