Talk given at Manchester WordCamp October ’15
Using Composer to
Tom de Bruin
“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.”
composer.json and composer.lock and composer
install and composer update
• composer install
• installs everything if .lock ﬁle doesn’t exist, writes .lock ﬁle.
• subsequently, brings everything up to date with what’s in the .lock
• composer update
• brings everything in your .json up to date, and updates the .lock ﬁle.
• Always run composer install on the server.
• Composer sees that .json and .lock match, installs everything.
• This can be confusing. Read all about it on http://daylerees.com/
composer-primer/ and https://adamcod.es/2013/03/07/composer-
packagist for WP
WP’s ﬁle structure
You can’t put your plugins in the vendor folder.
‛ Change the location, and name, of wp-conﬁg with a setting in
your wp-conﬁg.php ﬁle.
deﬁne('WP_CONTENT_DIR', $_SERVER['DOCUMENT_ROOT'] . '/app');
deﬁne('WP_CONTENT_URL', 'http://' . $_SERVER['HTTP_HOST'] . '/app');
Composer has many powers
• Register other repos (e.g. GitHub, BitBucket, …)
• Post install scripts
• And many more…
You don’t commit your dependencies.
At deployment you run composer install on the server.
Keeping in Sync
same as it ever was…
Tom de Bruin @deadlyhiﬁ