Slide 1

Slide 1 text

Using Composer to manage WP Tom de Bruin @deadlyhifi

Slide 2

Slide 2 text

“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.” https://getcomposer.org/ https://packagist.org/

Slide 3

Slide 3 text

https://packagist.org/packages/guzzlehttp/guzzle

Slide 4

Slide 4 text

https://getcomposer.org/doc/articles/versions.md#caret http://semver.org/

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

composer.json and composer.lock and composer install and composer update • composer install • installs everything if .lock file doesn’t exist, writes .lock file. • subsequently, brings everything up to date with what’s in the .lock file. • composer update • brings everything in your .json up to date, and updates the .lock file. • 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- install-vs-composer-update.html

Slide 7

Slide 7 text

packagist for WP http://wpackagist.org/

Slide 8

Slide 8 text

WP’s file structure You can’t put your plugins in the vendor folder. https://codex.wordpress.org/Editing_wp-config.php#Moving_wp-content_folder

Slide 9

Slide 9 text

https://codex.wordpress.org/Editing_wp-config.php#Moving_wp-content_folder ‛ Change the location, and name, of wp-config with a setting in your wp-config.php file. define('WP_CONTENT_DIR', $_SERVER['DOCUMENT_ROOT'] . '/app'); define('WP_CONTENT_URL', 'http://' . $_SERVER['HTTP_HOST'] . '/app');

Slide 10

Slide 10 text

https://github.com/composer/installers#custom-install-paths

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

Composer has many powers • require-dev • Register other repos (e.g. GitHub, BitBucket, …) • Post install scripts • And many more…

Slide 13

Slide 13 text

https://github.com/deadlyhifi/wp-gate8 https://roots.io/bedrock/

Slide 14

Slide 14 text

https://roots.io/bedrock/docs/environment-variables/

Slide 15

Slide 15 text

.gitignore You don’t commit your dependencies. https://getcomposer.org/doc/faqs/should-i-commit-the-dependencies-in-my-vendor-directory.md

Slide 16

Slide 16 text

Deployment At deployment you run composer install on the server. http://stackoverflow.com/questions/21721495/how-to-deploy-correctly-when-using-composers-develop-production-switch

Slide 17

Slide 17 text

Keeping in Sync same as it ever was… https://codex.wordpress.org/Editing_wp-config.php#Disable_Plugin_and_Theme_Update_and_Installation Pic: https://www.flickr.com/photos/ericbegin/1281728810

Slide 18

Slide 18 text

Questions? Tom de Bruin @deadlyhifi Read this…
 https://roots.io/using-composer-with-wordpress/ http://composer.rarst.net/ http://www.smashingmagazine.com/2014/03/better-dependency- management-team-based-wordpress-projects-composer/ Use this… https://roots.io/bedrock/ https://github.com/deadlyhifi/wp-gate8