{"id":28431,"date":"2018-03-14T04:56:06","date_gmt":"2018-03-14T02:56:06","guid":{"rendered":"https:\/\/mamchenkov.net\/wordpress\/?p=28431"},"modified":"2018-03-14T04:56:06","modified_gmt":"2018-03-14T02:56:06","slug":"updating-wordpress-with-composer-and-wp-cli","status":"publish","type":"post","link":"https:\/\/mamchenkov.net\/wordpress\/2018\/03\/14\/updating-wordpress-with-composer-and-wp-cli\/","title":{"rendered":"Updating WordPress with Composer and WP-CLI"},"content":{"rendered":"<!-- google_ad_section_start -->\n<p>The other day I came across <a href=\"https:\/\/markjaquith.wordpress.com\/2018\/02\/12\/updating-plugins-using-git-and-wp-cli\/\">this blog post<\/a> by\u00a0<a href=\"http:\/\/markjaquith.com\/\">Mark Jaquith<\/a>, who is one of the lead contributors to WordPress, in which he describes his process of updating WordPress plugins with WP-CLI and Git.\u00a0 I think a lot of people these days are trying to use Git for version control and automate their deployments, so WordPress developers aren&#8217;t an exception, and Mark&#8217;s post is a useful resource for that.<\/p>\n<p>With that said, however, I think there is a better.\u00a0 <a href=\"https:\/\/qobo.biz\/\">At work<\/a>, we&#8217;ve been dealing with quite a few WordPress-based projects, and automation of builds and deploys is very important to us.\u00a0 So we&#8217;ve taken a different approach.<\/p>\n<p>The initial inspiration for our approach was taken from <a href=\"https:\/\/roots.io\/using-composer-with-wordpress\/\">this blog post<\/a> by\u00a0<a href=\"https:\/\/twitter.com\/swalkinshaw\">Scott Walkinshaw<\/a> of the amazing <a href=\"https:\/\/roots.io\/\">Roots<\/a> team.<\/p>\n<p>Yes, that&#8217;s right, we use <a href=\"https:\/\/getcomposer.org\/\">Composer<\/a> to manage the WordPress, plugins and themes, both during the initial installation and the upgrades later.\u00a0 But we&#8217;ve taken it a step further by also integrating the <a href=\"http:\/\/wp-cli.org\/\">WP-CLI<\/a> to our setup, which you can find in our <a href=\"https:\/\/github.com\/QoboLtd\/project-template-wordpress\">project-template-wordpress<\/a> GitHub repository.<\/p>\n<p>I have oversimplified both the development and deployment process below, mostly for clarity.\u00a0 \u00a0(We do a lot more automation for our needs.)<\/p>\n<p><strong>During the development<\/strong>:<\/p>\n<ol>\n<li>Configure Composer to install WordPress into the <em>webroot\/wp<\/em> folder.<\/li>\n<li>Configure Composer to install plugins and themes into <em>webroot\/wp-content<\/em> folder. (Notice: we use a different wp-content folder location from the default WordPress one).<\/li>\n<li>Adjust <em>wp-config.php<\/em> for the new paths and drop it into the <em>webroot\/<\/em> folder.<\/li>\n<li>Add Composer&#8217;s <em>vendor\/<\/em> folder, and both <em>webroot\/wp<\/em> and <em>webroot\/wp-content<\/em> to <em>.gitignore.<\/em><\/li>\n<li>Add all required themes and plugins to the <em>composer.json<\/em>.<\/li>\n<li>Run <em>composer update<\/em> to create or update the <em>composer.lock<\/em> file.<\/li>\n<li>Commit both <em>composer.json<\/em> and <em>composer.lock<\/em>, as well as .gitignore and any other files you modified.<\/li>\n<li>Add a WP-CLI script that automates activation of plugins and sets the current theme.<\/li>\n<li>Push your changes to the git repository.<\/li>\n<\/ol>\n<p><strong>During the deployment<\/strong>:<\/p>\n<ol>\n<li>Clone or pull the changes from the git repository.<\/li>\n<li>Run <em>composer install<\/em> to fetch and install specific versions of WordPress, plugins, and themes, from the composer.lock file.<\/li>\n<li>Run the WP-CLI script to finalize the installation or update with the plugin activation, theme selection, etc.<\/li>\n<\/ol>\n<p>While it might look a little bit more complicated than what Mark and Scott described in their respective blog posts, I think this is a better approach for the following reasons:<\/p>\n<ol>\n<li><strong>Use a specialized tool to solve each problem<\/strong>.\u00a0 \u00a0Git is great for version control, so that&#8217;s what it should do.\u00a0 Composer is great for managing dependencies, and that&#8217;s what WordPress and its themes and plugins are for your project.\u00a0 WP-CLI is great for automating WordPress tasks.<\/li>\n<li><strong>Keep the git repository clean and simple<\/strong>.\u00a0 When working on a project, we never ever modify the code of the WordPress or any of its themes or plugins.\u00a0 And our setup enforces this approach.\u00a0 If you need to change the WordPress source code for a particular project, you are probably doing something wrong.\u00a0 If you need to change the plugin&#8217;s source code or the theme&#8217;s source code, you are probably doing something wrong again.\u00a0 Instead create child theme or your own version of the plugin and install those with Composer, keeping the plugin or theme related code changes in a separate repository.<\/li>\n<li><strong>Easily extendable and customizeable<\/strong>.\u00a0 Git, composer, and WP-CLI are great tools and we love using them.\u00a0 But the world is moving forward and there are constantly more and better tools to help with the complexities of the web development.\u00a0 Our setup expands and extends to welcome any tools that we find useful.\u00a0 For example, we have integrated with <a href=\"https:\/\/robo.li\/\">Robo<\/a>, PHPUnit and PHP Code Sniffer, TravisCI, BitBucket Pipelines, and many other tools over time.\u00a0 We&#8217;ve also said good bye to a few that became obsolete or to which we found better alternatives.<\/li>\n<\/ol>\n<p>Anyways, <a href=\"https:\/\/github.com\/QoboLtd\/project-template-wordpress\">project-template-wordpress<\/a> works quite well for us and I hope you&#8217;ll find it useful.\u00a0 Give it a try and <a href=\"https:\/\/github.com\/QoboLtd\/project-template-wordpress\/issues\/new\">let us know<\/a> if you find any issues or improvements.\u00a0 \u00a0Pull Requests are welcome. :)<\/p>\n<!-- google_ad_section_end -->\n","protected":false},"excerpt":{"rendered":"<!-- google_ad_section_start -->\n<p>The other day I came across this blog post by\u00a0Mark Jaquith, who is one of the lead contributors to WordPress, in which he describes his process of updating WordPress plugins with WP-CLI and Git.\u00a0 I think a lot of people these days are trying to use Git for version control and automate their deployments, so &hellip; <a href=\"https:\/\/mamchenkov.net\/wordpress\/2018\/03\/14\/updating-wordpress-with-composer-and-wp-cli\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Updating WordPress with Composer and WP-CLI<\/span><\/a><\/p>\n<!-- google_ad_section_end -->\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"Updating WordPress with Composer and WP-CLI #WebDev #PHP #WordPress #hosting #deployment #upgrades #WPCLI #composer","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"_links_to":"","_links_to_target":""},"categories":[1,18,133,62,1334,60],"tags":[3489,1586,3043,38,1330,3012,3459],"keyring_services":[],"class_list":["post-28431","post","type-post","status-publish","format-standard","hentry","category-general","category-programming","category-sysadmin","category-technology","category-web-work","category-wordpress","tag-composer","tag-deployment","tag-mark-jaquith","tag-php","tag-web-development","tag-wordpress-plugins","tag-wp-cli"],"aioseo_notices":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack-related-posts":[{"id":16512,"url":"https:\/\/mamchenkov.net\/wordpress\/2012\/07\/18\/wp-help-build-a-help-system-into-your-wordpress-project\/","url_meta":{"origin":28431,"position":0},"title":"WP Help &#8211; build a help system into your WordPress project","author":"Leonid Mamchenkov","date":"July 18, 2012","format":false,"excerpt":"Mark Jaquith has updated his WP Help plugin to version 1.0. \u00a0This is very handy for those people who build WordPress-based projects for other people to use. Anything from your mother's blog to a super-duper custom WordPress application could a few pages of help, explaining \u00a0how to do things. \u00a0And\u2026","rel":"","context":"In &quot;All&quot;","block_context":{"text":"All","link":"https:\/\/mamchenkov.net\/wordpress\/category\/general\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/mamchenkov.net\/wordpress\/wp-content\/uploads\/2012\/07\/WP-Help-1.0.png?fit=584%2C284&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/mamchenkov.net\/wordpress\/wp-content\/uploads\/2012\/07\/WP-Help-1.0.png?fit=584%2C284&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/mamchenkov.net\/wordpress\/wp-content\/uploads\/2012\/07\/WP-Help-1.0.png?fit=584%2C284&ssl=1&resize=525%2C300 1.5x"},"classes":[]},{"id":27386,"url":"https:\/\/mamchenkov.net\/wordpress\/2017\/03\/05\/terminals-are-sexy\/","url_meta":{"origin":28431,"position":1},"title":"Terminals Are Sexy","author":"Leonid Mamchenkov","date":"March 5, 2017","format":false,"excerpt":"Terminals are sexy is a\u00a0curated list of Terminal frameworks, plugins & resources for CLI lovers. \u00a0There is plenty of links to applications, plugins and configurations. \u00a0For me personally, the most useful one was the link to sensible Bash configuration.","rel":"","context":"In &quot;All&quot;","block_context":{"text":"All","link":"https:\/\/mamchenkov.net\/wordpress\/category\/general\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/mamchenkov.net\/wordpress\/wp-content\/uploads\/2017\/03\/terminals-are-sexy-500x216.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":27623,"url":"https:\/\/mamchenkov.net\/wordpress\/2017\/05\/25\/what-is-wp-cli-a-beginners-guide\/","url_meta":{"origin":28431,"position":2},"title":"What Is WP-CLI? A Beginner\u2019s Guide","author":"Leonid Mamchenkov","date":"May 25, 2017","format":false,"excerpt":"WP-CLI is a super useful tool, which I use on a daily basis, and I wish more people knew about. \u00a0Gladly, there is now \"What Is WP-CLI? A Beginner\u2019s Guide\", which explains what it is, how to install it, how to use it, and where to go from there.","rel":"","context":"In &quot;All&quot;","block_context":{"text":"All","link":"https:\/\/mamchenkov.net\/wordpress\/category\/general\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":19433,"url":"https:\/\/mamchenkov.net\/wordpress\/2014\/01\/16\/wp-cli-command-line-interface-for-wordpress\/","url_meta":{"origin":28431,"position":3},"title":"WP-CLI &#8211; command line interface for WordPress","author":"Leonid Mamchenkov","date":"January 16, 2014","format":"link","excerpt":"WP-CLI - command line interface for WordPress Oh. My. God! How did I not know about this earlier???","rel":"","context":"In &quot;All&quot;","block_context":{"text":"All","link":"https:\/\/mamchenkov.net\/wordpress\/category\/general\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":26275,"url":"https:\/\/mamchenkov.net\/wordpress\/2016\/07\/24\/wordpress-plugins-demo-data-creator\/","url_meta":{"origin":28431,"position":4},"title":"WordPress Plugins : Demo Data Creator","author":"Leonid Mamchenkov","date":"July 24, 2016","format":false,"excerpt":"Here is a useful plugin for all of you, WordPress developers - Demo Data Creator. \u00a0 It generates a whole lot of test \/ demo data and populates your WordPress site with it. \u00a0No more lengthy copy-pastes of Lorem Ipsum into posts and pages, single user (hi admin) installations, and\u2026","rel":"","context":"In &quot;All&quot;","block_context":{"text":"All","link":"https:\/\/mamchenkov.net\/wordpress\/category\/general\/"},"img":{"alt_text":"demo-data-creator","src":"https:\/\/i0.wp.com\/mamchenkov.net\/wordpress\/wp-content\/uploads\/2016\/07\/demo-data-creator-302x500.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":24785,"url":"https:\/\/mamchenkov.net\/wordpress\/2015\/09\/30\/packaging-third-party-plugins-with-your-wordpress-theme\/","url_meta":{"origin":28431,"position":5},"title":"Packaging third-party plugins with your WordPress theme","author":"Leonid Mamchenkov","date":"September 30, 2015","format":false,"excerpt":"Many a time I've been involved in building a custom WordPress theme, which relied or benefited from some plugins being installed and activated. \u00a0I've always had an ad hoc solution to the problem, with my own installation scripts, WP-CLI mockery, etc. \"Packaging third-party plugins with your WordPress theme using TGM\u2026","rel":"","context":"In &quot;All&quot;","block_context":{"text":"All","link":"https:\/\/mamchenkov.net\/wordpress\/category\/general\/"},"img":{"alt_text":"wordpress theme plugins","src":"https:\/\/i0.wp.com\/mamchenkov.net\/wordpress\/wp-content\/uploads\/2015\/09\/wordpress-theme-plugins-500x157.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]}],"jetpack_sharing_enabled":true,"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/posts\/28431","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/comments?post=28431"}],"version-history":[{"count":0,"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/posts\/28431\/revisions"}],"wp:attachment":[{"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/media?parent=28431"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/categories?post=28431"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/tags?post=28431"},{"taxonomy":"keyring_services","embeddable":true,"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/keyring_services?post=28431"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}