Tips & Tricks with Composer

I'll be updating this post with new tips and tricks about composer as my personal list of useful commands and configurations.

Install composer package globally

composer global require "codeception/codeception:*"  

Remove dev dependencies

composer update --no-dev  

We could use the tag --no-dev when installing our dependencies and avoid the dev ones

Avoid API rate limit and OAuth tokens

composer config -g <oauthtoken>  

Composer troubleshooting guide

Install a single library with a specific version and stability flag

composer require doctrine/doctrine-fixtures-bundle:2.1.*@dev  

Update a single library with composer

composer update doctrine/doctrine-fixtures-bundle  

How to install a composer new dependency without updating old ones

 Composer create-project command

Create a project from branch

dev-v/1.7 will be the branch we want to install.

composer create-project block8/phpci /opt/phpci --keep-vcs --no-dev "dev-v/1.7"  
Create a project from private repo

The option --repository-url= will indicate where is our private repo form where create the new project

composer create-project block8/phpci /opt/phpci --keep-vcs --no-dev --repository-url=  

--repository-url= will be looking for a package.json file if there is non on that address it will throw an error

Composer create project from private repo

Global configuration

You can add to your $COMPOSER_HOME a file called config.json with your default composer configuration to be used across all your projects.


    "config": {
        "preferred-install": "dist",
        "github-oauth": {
            "": "jisaf7y783oh32ho3h891h1e2h8iijfsi8"

In the example below preferred-install dist option will be use and a specific GitHub token will be use for authentication with the domain

Edit your vendor dependencies directly

For practical reasons, you may prefer cloning sources instead of downloading packages. For instance, this can be useful to edit a library directly in the vendor directory to test the behaviour of your application with that change. The --prefer-source option will force cloning sources instead of downloading an archive:

$ composer update me/repo --prefer-source

Then to see modified files in your vendor:

$ composer status -v
You have changes in the following dependencies:  
    M Request.php

Composer will also tells you when you try to update a vendor that has been modified, and asks if you want to discard the changes:

$ composer update
Loading composer repositories with package information  
Updating dependencies  
  - Updating me/repo v1.2.0 (v1.2.0- => v1.2.0)
    The package has modified files:
    M Request.php
    Discard changes [y,n,v,s,?]?

Prefer source to edit your vendors

Installing package from local git repository

"repositories": [

If your package is published on packagist, you need to add --prefer-source option to force installation from VCS.

Installing package from local git repository

Install package from a development branch (forked project)

"repositories": [

Notice: the differences between me/one-repository and other/one-repository

There is another way to achieve this using inline-aliases in our composer.json file like:


"require" : {
    "other/repository": "dev-my-branch as the-other-expected-branch"

Have composer use development branches