Composer is an opensource PHP packaging system to manage dependencies.
This makes it easy to adapt package installs and updates to your workflow, allowing you to test new/updated packages in a development environment, put the changes in your version control system (git, Subversion, Mercurial, etc.), pull in those changes on a staging environment and, when approved, put it in production.
composer.phar or composer ?
The following examples use a composer install
global command, as alternative use php composer.phar <command>
.
Read the answer in the FAQ: What Composer command-line do you have to use ?
Technical prerequisites
Composer requires PHP 5.3.2+ to run.
Useful Composer commands for System Administrators
Note: as usual with CLI, you can type:
$> php composer.phar help [--xml] [--format="..."] [--raw] [command_name]
to get help for the command.
On this page you will find some useful commands and an extract of the Composer Documentation. The interesting options part is an extract of available options
show
The show
command displays detailed information about a package, or lists all available packages.
Usage:
require
The require
command adds required packages to your composer.json and installs them. If you do not want to install the new dependencies immediately, you can call it with --no-update
Usage:
Interesting options
--prefer-source | Forces installation from package sources when possible, including VCS information. |
--prefer-dist | Forces installation from package dist even for dev versions. |
--no-progress | Do not output download progress. |
--no-update | Disables the automatic update of the dependencies. |
--update-with-dependencies | Allows inherited dependencies to be updated with explicit dependencies. |
search
The search
command searches for packages by its name.
Example :
can return to you a list like this:
validate
The validate
command validates a given composer.json.
Usage
Interesting options
option | description |
---|---|
--no-check-all | Do not make a complete validation |
--profile | Display timing and memory usage information |
--working-dir (-d) | If specified, use the given directory as working directory. |
Automate installation
Note that you can add some scripts to the Composer dependencies installation.
The available events are :
- pre-install-cmd
- post-install-cmd
- pre-update-cmd
- post-update-cmd
- pre-status-cmd
- post-status-cmd
- pre-package-install
- post-package-install
- pre-package-update
- post-package-update
- pre-package-uninstall
- post-package-uninstall
- pre-autoload-dump
- post-autoload-dump
- post-root-package-install
- post-create-project-cmd
- pre-archive-cmd
- post-archive-cmd