Skip to main content
Composer 
the right way 
Rafael Dohms 
@rdohms
photo: smileymanwithahat
photo: Rob Allen
The Composer Cookbook 
https://leanpub.com/composer-cookbook
photo: 18millionpixels
Library Publisher 
photo: 18millionpixels
Library Publisher 
Library Consumer 
photo: 18millionpixels
Library Publisher 
Library 
Library Consumer 
photo: 18millionpixels
Library Publisher 
Library 
Packagist 
Library Consumer 
photo: 18millionpixels
photo: 18millionpixels
{ 
"require": { 
"monolog/monolog": “2.0” 
} 
} 
photo: 18millionpixels
{ 
"require": { 
"monolog/monolog": “2.0” 
} 
} 
{ 
"name": “monolog/monolog” 
... 
} 
photo: 18millionpixels
{ 
"require": { 
"monolog/monolog": “2.0” 
} 
} 
{ 
"name": “monolog/monolog” 
... 
} 
./composer.json has been updated 
Loading composer repositories with package information 
Updating dependencies (including require-dev) 
Your requirements could not be resolved to an installable set of packages. 
! 
Problem 1 
- The requested package monolog/monolog could not be found in any version, there may be a typo in the package name. 
! 
Potential causes: 
- A typo in the package name 
- The package is not available in a stable-enough version according to your minimum-stability setting 
see <https://groups.google.com/d/topic/composer-dev/_g3ASeIFlrc/discussion> for more details. 
! 
Read <http://getcomposer.org/doc/articles/troubleshooting.md> for further common problems. 
! 
Installation failed, reverting ./composer.json to its original content. 
photo: 18millionpixels
{ 
"require": { 
___ 
~1.1 
"monolog/monolog": “2.0” 
} 
} 
{ 
"name": “monolog/monolog” 
... 
} 
./composer.json has been updated 
Loading composer repositories with package information 
Updating dependencies (including require-dev) 
Your requirements could not be resolved to an installable set of packages. 
! 
Problem 1 
- The requested package monolog/monolog could not be found in any version, there may be a typo in the package name. 
! 
Potential causes: 
- A typo in the package name 
- The package is not available in a stable-enough version according to your minimum-stability setting 
see <https://groups.google.com/d/topic/composer-dev/_g3ASeIFlrc/discussion> for more details. 
! 
Read <http://getcomposer.org/doc/articles/troubleshooting.md> for further common problems. 
! 
Installation failed, reverting ./composer.json to its original content. 
photo: 18millionpixels
{ 
"require": { 
___ 
~1.1 
"monolog/monolog": “2.0” 
} 
} 
{ 
"name": “monolog/monolog” 
... 
} 
./composer.json has been updated 
Loading composer repositories with package information 
Updating dependencies (including require-dev) 
Your requirements could not be resolved to an installable set of packages. 
! 
Problem 1 
- Installing psr/log (1.0.0) 
Loading from cache 
! 
- Installing monolog/monolog (1.11.0) 
- The requested package monolog/monolog could not be found in any version, there may be a typo in the package name. 
! 
Downloading: 100% 
Potential causes: 
- A typo in the package name 
- The package is not available in a stable-enough version according to your minimum-stability setting 
! 
monolog/monolog suggests installing graylog2/gelf-php (Allow sending log messages to a GrayLog2 server) 
[...] 
monolog/see <https://monolog groups.suggests google.installing com/d/ext-topic/mongo composer-(Allow dev/_sending g3ASeIFlrc/log messages discussion> to a for MongoDB more server) 
details. 
monolog/! 
monolog suggests installing aws/aws-sdk-php (Allow sending log messages to AWS services like DynamoDB) 
monolog/Read <http://monolog getcomposer.suggests org/installing doc/articles/rollbar/troubleshooting.rollbar (Allow md> sending for further log messages common to problems. 
Rollbar) 
! 
Writing lock file 
Installation Generating autoload failed, files 
reverting ./composer.json to its original content. 
photo: 18millionpixels
composer
! composer.json composer
! composer.json composer 
! composer.lock
! composer.json composer 
! composer.lock
discovery Packagist 
" 
! composer.json composer 
! composer.lock
discovery Packagist source 
" 
Repository 
# 
! composer.json composer 
! composer.lock
discovery source 
installation 
Packagist 
" 
Vendor 
Folder 
$ 
Repository 
# 
! composer.json composer 
! composer.lock
Library Publisher 
$ composer init
Library Publisher 
$ composer init 
Library Consumer 
$ composer require <vendor>/<package>
Tip 
$ composer require monolog/monolog 
Using version ~1.11 for monolog/monolog
Composer for 
Library Publishers
vendor / package 
Library Publisher Unique vendor names
pick your own 
unique vendor 
Library Publisher Unique vendor names
or join a collective 
Library Publisher Unique vendor names
! README 
% CHANGELOG 
& LICENSE 
Library Publisher What’s in your library?
! README 
% CHANGELOG 
& LICENSE 
' What problem does it solve? 
' Usage examples 
' Install instructions 
' How can I contribute? 
Library Publisher What’s in your library?
! README 
% CHANGELOG 
& LICENSE 
' What problem does it solve? 
' Usage examples 
' Install instructions 
' How can I contribute? 
' List relevant changes 
' Make BC breaks prominent 
' Show examples of how to upgrade 
Library Publisher What’s in your library?
! README 
% CHANGELOG 
& LICENSE 
' What problem does it solve? 
' Usage examples 
' Install instructions 
' How can I contribute? 
' List relevant changes 
' Make BC breaks prominent 
' Show examples of how to upgrade 
' Pick one that reflects your values 
' choosealicense.com can help 
Library Publisher What’s in your library?
1 . 2 . 3 
major minor patch 
Library Publisher Semantic Versioning
1 . 2 . 3 
major minor patch 
Library Publisher Semantic Versioning 
Bug Fixes
New Features Bug Fixes 
1 . 2 . 3 
major minor patch 
Library Publisher Semantic Versioning
API / BC Breaks New Features Bug Fixes 
1 . 2 . 3 
major minor patch 
Library Publisher Semantic Versioning
Tag it and Bag it 
Library Publisher Tagging
# Simple Tag 
$ git tag v1.2.3 
! 
! 
! 
# Annotated Tag 
$ git tag -a v1.2.3 -m “Description of Release" 
Library Publisher Tagging
Library Publisher “I'm out" 
photo: jilliancorinne
Library Publisher “I'm out"
Click here and provide another 
Library Publisher “I'm out"
Library Publisher “I'm out"
Library Publisher “I'm out" 
coming 
soon
Pick the 
correct 
version 
Library Publisher Pick a Version
* the asterisk 
Library Publisher Pick a Version
* the asterisk ○ 
Library Publisher Pick a Version
~ the tilde 
Library Publisher Pick a Version
~1.2 
>=1.2.0, <2.0.0 
Library Publisher Pick a Version
~1.2 
>=1.2.0, <2.0.0 
Library Publisher Pick a Version 
)
~1.2.3 
>=1.2.0, <1.3 
Library Publisher Pick a Version
~1.2.3 
>=1.2.0, <1.3 
Library Publisher Pick a Version 
)
3rd party library 
"require": { 
"zendframework/zend-stdlib": “2.1.*”, 
"zendframework/zend-servicemanager": "2.1.*", 
}, 
! 
“require-dev": { 
“phpunit/phpunit": “~3.7” 
} 
Your application 
"require": { 
"zendframework/zend-stdlib": “~2.3”, 
"zendframework/zend-servicemanager": “~2.3", 
}, 
! 
“require-dev": { 
“phpunit/phpunit": “~4” 
} 
Library Publisher Pick a Version
3rd party library 
"require": { 
"zendframework/zend-stdlib": “2.1.*”, 
"zendframework/zend-servicemanager": "2.1.*", 
}, 
! 
“require-dev": { 
* 
“phpunit/phpunit": “~3.7” 
} 
Your application 
"require": { 
"zendframework/zend-stdlib": “~2.3”, 
"zendframework/zend-servicemanager": “~2.3", 
}, 
! 
“require-dev": { 
“phpunit/phpunit": “~4” 
} 
Library Publisher Pick a Version
3rd party library 
"require": { 
"zendframework/zend-stdlib": “2.1.*”, 
"zendframework/zend-servicemanager": "2.1.*", 
}, 
! 
“require-dev": { 
* 
“phpunit/phpunit": “~3.7” 
} 
Your application 
"require": { 
"zendframework/zend-stdlib": “~2.3”, 
"zendframework/zend-servicemanager": “~2.3", 
}, 
! 
“require-dev": { 
“phpunit/phpunit": “~4” 
} 
Library Publisher Pick a Version
3rd party library 
"require": { 
"zendframework/zend-stdlib": “2.1.*”, 
"zendframework/zend-servicemanager": "2.1.*", 
}, 
! 
“require-dev": { 
* 
“phpunit/phpunit": “~3.7” 
} 
Your application 
"require": { 
"zendframework/zend-stdlib": “~2.3”, 
"zendframework/zend-servicemanager": “~2.3", 
}, 
! 
“require-dev": { 
“phpunit/phpunit": “~4” 
} 
Library Publisher Pick a Version 
~2.1
Composer for 
Library Consumers
install or update? 
Library Consumer Install or update?
Make sure you have 
installed the last 
updates from other 
developers. 
? 
install or update 
Library Consumer Install or update?
Make sure you have 
installed the last 
updates from other 
developers. 
? 
install or update 
Library Consumer Install or update?
Deploying a new 
release of your 
application to 
production. 
? 
install or update 
Library Consumer Install or update?
Deploying a new 
release of your 
application to 
production. 
? 
install or update 
Library Consumer Install or update?
Checked out a new 
project and want to 
start coding. 
? 
install or update 
Library Consumer Install or update?
Checked out a new 
project and want to 
start coding. 
? 
install or update 
Library Consumer Install or update?
Grab new versions for 
the dependencies of 
your project. 
? 
install or update 
Library Consumer Install or update?
Grab new versions for 
the dependencies of 
your project. 
? 
install or update 
Library Consumer Install or update?
Your application 
$ 
Public 
Repository 
# 
! composer.lock 
composer install 
composer update 
Library Consumer Install or update?
Your application 
$ 
Public 
Repository 
# 
! composer.lock 
read 
composer install 
composer update 
Library Consumer Install or update?
Your application 
$ 
read grab version 
Public 
Repository 
# 
! composer.lock 
composer install 
composer update 
Library Consumer Install or update?
Your application 
$ 
read grab version 
Public 
Repository 
# 
! composer.lock 
check latest compatible release 
composer install 
composer update 
Library Consumer Install or update?
Your application 
$ 
read grab version 
Public 
Repository 
# 
! composer.lock 
check latest compatible release 
Library Consumer Install or update? 
update 
composer install 
composer update
commit your lock file 
Library Consumer Install or update?
Tip 
$ composer update --lock 
Library Consumer Install or update?
Pick the 
correct 
version 
Library Consumer Version Selection
dev-master 
Library Consumer Version Selection
Library Consumer Version Selection
Library Consumer Version Selection
found a bug? 
Library Consumer Using forks
Tip 
$ composer install --prefer-source 
Library Consumer Using forks
Library Consumer Using forks
patch it, 
Library Consumer Using forks
patch it, 
fork it, 
Library Consumer Using forks
patch it, 
fork it, 
push it… 
Library Consumer Using forks
patch it, 
fork it, 
push it… 
wait for it. 
Library Consumer Using forks
patch it, 
fork it, 
push it… 
wait for it. 
Library Consumer Using forks
symfony/symfony 
Library Consumer Using forks
symfony/symfony 
Library Consumer Using forks 
rdohms/symfony
symfony/symfony 
Library Consumer Using forks 
rdohms/symfony 
"repositories": [ 
{ 
"type": "vcs", 
"url": "https://github.com/rdohms/symfony" 
} 
]
symfony/symfony 
Library Consumer Using forks 
rdohms/symfony 
"repositories": [ 
{ 
"type": "vcs", 
"url": "https://github.com/rdohms/symfony" 
} 
] 
+
Tip 
$ composer show -v symfony/symfony 
Library Consumer Using forks
Do not put 
forked repositories 
on packagist 
, 
Library Consumer Using forks
Tip 
"require": { 
"symfony/symfony": "dev-my-patch as 2.5.0" 
} 
Library Consumer Using forks
Composer 
and 
production 
Library Consumer Composer and deployments
Packagist 
. 
Production 
Server 
- 
Library Consumer Composer and deployments
Packagist 
. 
/ Man in the middle 
Production 
Server 
- 
Library Consumer Composer and deployments
Build Server 
0 
Library Consumer Composer and deployments 
Production 
Server 
- 
" 
Packagist 
. 
/ Man in the middle
, 
$ composer install --prefer-dist --no-dev —optimize-autoloader 
Library Consumer Composer and deployments
, 
$ composer install --prefer-dist --no-dev —optimize-autoloader 
Library Consumer Composer and deployments