Introduction
Composer is a tool for dependency management in PHP. It allows you to declare the libraries your project depends on and it will manage (install/update) them for you.
Dependency management
Composer is not a package manager in the same sense as Yum or Apt are. Yes, it deals with “packages” or libraries, but it manages them on a per-project basis, installing them in a directory (e.g. vendor
) inside your project. By default, it does not install anything globally. Thus, it is a dependency manager. It does however support a “global” project for convenience via the global command.
This idea is not new and Composer is strongly inspired by node’s npm and ruby’s bundler.
Suppose:
- You have a project that depends on a number of libraries.
- Some of those libraries depend on other libraries.
Composer:
- Enables you to declare the libraries you depend on.
- Finds out which versions of which packages can and need to be installed, and installs them (meaning it downloads them into your project).
- You can update all your dependencies in one command.
See the Basic usage chapter for more details on declaring dependencies.
Download Composer
WARNING
Please do not redistribute the install code. It will change with every version of the installer. Instead, please link to this page or check how to install Composer programmatically.
To quickly install Composer in the current directory, run the following script in your terminal. To automate the installation, use the guide on installing Composer programmatically.
This installer script will simply check some php.ini
settings, warn you if they are set incorrectly, and then download the latest composer.phar
in the current directory. The 4 lines above will, in order:
- Download the installer to the current directory
- Verify the installer SHA-384, which you can also cross-check here
- Run the installer
- Remove the installer
Most likely, you want to put the composer.phar
into a directory on your PATH, so you can simply call composer
from any directory (Global install), using for example:
For details, see the instructions on how to install Composer globally.