Command-line interface / Commands#

You've already learned how to use the command-line interface to do some things. This chapter documents all the available commands.

To get help from the command-line, simply call composer or composer list to see the complete list of commands, then --help combined with any of those can give you more information.

Global Options#

The following options are available with every command:

Process Exit Codes#


In the Libraries chapter we looked at how to create a composer.json by hand. There is also an init command available that makes it a bit easier to do this.

When you run the command it will interactively ask you to fill in the fields, while using some smart defaults.

php composer.phar init



The install command reads the composer.json file from the current directory, resolves the dependencies, and installs them into vendor.

php composer.phar install

If there is a composer.lock file in the current directory, it will use the exact versions from there instead of resolving them. This ensures that everyone using the library will get the same versions of the dependencies.

If there is no composer.lock file, Composer will create one after dependency resolution.



In order to get the latest versions of the dependencies and to update the composer.lock file, you should use the update command.

php composer.phar update

This will resolve all dependencies of the project and write the exact versions into composer.lock.

If you just want to update a few packages and not all, you can list them as such:

php composer.phar update vendor/package vendor/package2

You can also use wildcards to update a bunch of packages at once:

php composer.phar update vendor/*



The require command adds new packages to the composer.json file from the current directory. If no file exists one will be created on the fly.

php composer.phar require

After adding/changing the requirements, the modified requirements will be installed or updated.

If you do not want to choose requirements interactively, you can just pass them to the command.

php composer.phar require vendor/package:2.* vendor/package2:dev-master



The remove command removes packages from the composer.json file from the current directory.

php composer.phar remove vendor/package vendor/package2

After removing the requirements, the modified requirements will be uninstalled.



The global command allows you to run other commands like install, require or update as if you were running them from the COMPOSER_HOME directory.

This can be used to install CLI utilities globally and if you add $COMPOSER_HOME/vendor/bin to your $PATH environment variable. Here is an example:

php composer.phar global require fabpot/php-cs-fixer:dev-master

Now the php-cs-fixer binary is available globally (assuming you adjusted your PATH). If you wish to update the binary later on you can just run a global update:

php composer.phar global update

The search command allows you to search through the current project's package repositories. Usually this will be just packagist. You simply pass it the terms you want to search for.

php composer.phar search monolog

You can also search for more than one term by passing multiple arguments.



To list all of the available packages, you can use the show command.

php composer.phar show

If you want to see the details of a certain package, you can pass the package name.

php composer.phar show monolog/monolog

name     : monolog/monolog
versions : master-dev, 1.0.2, 1.0.1, 1.0.0, 1.0.0-RC1
type     : library
names    : monolog/monolog
source   : [git] 3d4e60d0cbc4b888fe5ad223d77964428b1978da
dist     : [zip] 3d4e60d0cbc4b888fe5ad223d77964428b1978da
license  : MIT

Monolog : src/

php >=5.3.0

You can even pass the package version, which will tell you the details of that specific version.

php composer.phar show monolog/monolog 1.0.2


browse / home#

The browse (aliased to home) opens a package's repository URL or homepage in your browser.



Lists all packages suggested by currently installed set of packages. You can optionally pass one or multiple package names in the format of vendor/package to limit output to suggestions made by those packages only.



The depends command tells you which other packages depend on a certain package. You can specify which link types (require, require-dev) should be included in the listing. By default both are used.

php composer.phar depends --link-type=require monolog/monolog




You should always run the validate command before you commit your composer.json file, and before you tag a release. It will check if your composer.json is valid.

php composer.phar validate



If you often need to modify the code of your dependencies and they are installed from source, the status command allows you to check if you have local changes in any of them.

php composer.phar status

With the --verbose option you get some more information about what was changed:

php composer.phar status -v

You have changes in the following dependencies:
    M README.mdown


To update Composer itself to the latest version, just run the self-update command. It will replace your composer.phar with the latest version.

php composer.phar self-update

If you would like to instead update to a specific release simply specify it:

php composer.phar self-update 1.0.0-alpha7

If you have installed Composer for your entire system (see global installation), you may have to run the command with root privileges

sudo composer self-update



The config command allows you to edit some basic Composer settings in either the local composer.json file or the global config.json file.

php composer.phar config --list


config [options] [setting-key] [setting-value1] ... [setting-valueN]

setting-key is a configuration option name and setting-value1 is a configuration value. For settings that can take an array of values (like github-protocols), more than one setting-value arguments are allowed.

See the Config chapter for valid configuration options.


Modifying Repositories#

In addition to modifying the config section, the config command also supports making changes to the repositories section by using it the following way:

php composer.phar config vcs


You can use Composer to create new projects from an existing package. This is the equivalent of doing a git clone/svn checkout followed by a "composer install" of the vendors.

There are several applications for this:

  1. You can deploy application packages.
  2. You can check out any package and start developing on patches for example.
  3. Projects with multiple developers can use this feature to bootstrap the initial application for development.

To create a new project using Composer you can use the "create-project" command. Pass it a package name, and the directory to create the project in. You can also provide a version as third argument, otherwise the latest version is used.

If the directory does not currently exist, it will be created during installation.

php composer.phar create-project doctrine/orm path 2.2.*

It is also possible to run the command without params in a directory with an existing composer.json file to bootstrap a project.

By default the command checks for the packages on



If you need to update the autoloader because of new classes in a classmap package for example, you can use "dump-autoload" to do that without having to go through an install or update.

Additionally, it can dump an optimized autoloader that converts PSR-0/4 packages into classmap ones for performance reasons. In large applications with many classes, the autoloader can take up a substantial portion of every request's time. Using classmaps for everything is less convenient in development, but using this option you can still use PSR-0/4 for convenience and classmaps for performance.



Deletes all content from Composer's cache directories.


Lists the name, version and license of every package installed. Use --format=json to get machine readable output.




To run scripts manually you can use this command, just give it the script name and optionally any required arguments.


If you think you found a bug, or something is behaving strangely, you might want to run the diagnose command to perform automated checks for many common problems.

php composer.phar diagnose


This command is used to generate a zip/tar archive for a given package in a given version. It can also be used to archive your entire project without excluded/ignored files.

php composer.phar archive vendor/package 2.0.21 --format=zip



To get more information about a certain command, just use help.

php composer.phar help install

Environment variables#

You can set a number of environment variables that override certain settings. Whenever possible it is recommended to specify these settings in the config section of composer.json instead. It is worth noting that the env vars will always take precedence over the values specified in composer.json.


By setting the COMPOSER env variable it is possible to set the filename of composer.json to something else.

For example:

COMPOSER=composer-other.json php composer.phar install

The generated lock file will use the same name: composer-other.lock in this example.


By setting this var you can specify the version of the root package, if it can not be guessed from VCS info and is not present in composer.json.


By setting this var you can make Composer install the dependencies into a directory other than vendor.


By setting this option you can change the bin (Vendor Binaries) directory to something other than vendor/bin.

http_proxy or HTTP_PROXY#

If you are using Composer from behind an HTTP proxy, you can use the standard http_proxy or HTTP_PROXY env vars. Simply set it to the URL of your proxy. Many operating systems already set this variable for you.

Using http_proxy (lowercased) or even defining both might be preferable since some tools like git or curl will only use the lower-cased http_proxy version. Alternatively you can also define the git proxy using git config --global http.proxy <proxy url>.


If you are behind a proxy and would like to disable it for certain domains, you can use the no_proxy env var. Simply set it to a comma separated list of domains the proxy should not be used for.

The env var accepts domains, IP addresses, and IP address blocks in CIDR notation. You can restrict the filter to a particular port (e.g. :80). You can also set it to * to ignore the proxy for all HTTP requests.


If you use a proxy but it does not support the request_fulluri flag, then you should set this env var to false or 0 to prevent Composer from setting the request_fulluri option.


If you use a proxy but it does not support the request_fulluri flag for HTTPS requests, then you should set this env var to false or 0 to prevent Composer from setting the request_fulluri option.


The COMPOSER_HOME var allows you to change the Composer home directory. This is a hidden, global (per-user on the machine) directory that is shared between all projects.

By default it points to /home/<user>/.composer on *nix, /Users/<user>/.composer on OSX and C:\Users\<user>\AppData\Roaming\Composer on Windows.


You may put a config.json file into the location which COMPOSER_HOME points to. Composer will merge this configuration with your project's composer.json when you run the install and update commands.

This file allows you to set repositories and configuration for the user's projects.

In case global configuration matches local configuration, the local configuration in the project's composer.json always wins.


The COMPOSER_CACHE_DIR var allows you to change the Composer cache directory, which is also configurable via the cache-dir option.

By default it points to $COMPOSER_HOME/cache on *nix and OSX, and C:\Users\<user>\AppData\Local\Composer (or %LOCALAPPDATA%/Composer) on Windows.


This env var controls the time Composer waits for commands (such as git commands) to finish executing. The default value is 300 seconds (5 minutes).


This env var controls the discard-changes config option.


If set to 1, this env var will make Composer behave as if you passed the --no-interaction flag to every command. This can be set on build boxes/CI.


If set to 1, this env disables the warning about having xdebug enabled.

Libraries | Schema

Found a typo? Something is wrong in this documentation? Just fork and edit it!