Best way to combine Composer+Wordpress & Roots+Node+Grunt workflows?

@swalkinshaw Hi Scott, I was wondering how the new screencast is comming along. I have a new website pending and would love to use what you can teach us for the new deployment.

Thanks again for all your work,

Mauro

By the end of this week I promise (weekend)! Finally have a good 4-5 days of more time to finish it.

2 Likes

For those waiting on the screencast, Iā€™m 90% done and it looks like Iā€™ll break my promise a bit but the screencast should be up in the next day or two. Unfortunately itā€™s always the editing and final publishing that take the longest :frowning:

2 Likes

Screencast is finally out! http://roots.io/screencasts/deploying-wordpress-with-capistrano/

Sorry for the long wait but making these screencasts is actually pretty time consuming! Iā€™ll probably start a separate thread for feedback/questions about it.

2 Likes

Awesome stuffs gonna get it when I get back home! Canā€™t wait!

Iā€™ve made a thread dedicated to the screencast/general Capistrano talk here: Deploying WordPress with Capistrano screencast

Keeping databases in sync in my opinion is one of the more difficult challenges to solve, yet least talked about on forums about deployment. After a ton of different approaches, hereā€™s what I recommend:

  1. WP Migrate DB Pro If youā€™re a WP developer, itā€™s one of the best ways to spend $99. It is SO easy to push and pull databases between local, dev, prod, etc., including updating URLs that have been serialized in widgets. You can push the entire db, or select which tables. This helps if you simply update the wp_options table or wp_posts/wp_postmeta. The only downside is that currently you need to run it through a browser in the WP admin, but they are potentially working on a command line solution. They also have a beta add-on for keeping media files in sync, due out in the main plugin soon.

  2. The next best option is to set up wp-cli. This allows you to run WordPress commands via the command line, and you can hook in and create your own. It has a built in search-replace function to update URLs & serialized data (it actually used the interconnectit search-and-replace mentioned elsewhere here). What I do to prepare the database is to use the search-replace function to update the URLs, export it via wp-cli, and then take that dump.sql and import it into the target database somehow. Easiest is via phpMyAdmin or Sequel Pro. OR, I have also written simple scripts that SCP the dump to the server and then import it via mysql command line.

  3. Use interconnectit search-and-replace in your project. This has a browser base or CLI option. Iā€™ve used the CLI as a part of a custom deploy bash script.

  4. Use WP Engine. They have a push button production to/from staging setup which also allows for full or table-based db migration. Downside is that you still need to do one of the other options above for deployment to/from local. And, if you want to do any of the great Capistrano kind of stuff mentioned in this post, you are out of luck with WP Engine since they do not allow SSH access.

2 Likes

Hey merchantguru,

Wish I read this post before i posted to the capistrano screencast thread.

I too am looking to solve the database issue.

Option 2 sounds like the best plan, although i just use sed for find and replace, works a treat.

For all the love (or addiction) I have for Railsless Capistrano it always seemed wrong. Better to stand on the shoulders of giants: http://tech.toptable.co.uk/blog/2013/08/08/grunt-your-deployments-too/

I realize Iā€™m super late to the game on this but just thought youā€™d find it interesting. Iā€™ll be giving this a whirl in an upcoming Roots site.

1 Like

Keep in mind that Capistrano v3 was rewritten and no longer has anything Rails specific in it. You actually need to require Rails gems for it if you want. v3 is generally must better, simpler, and faster.

Sed works to find and replace URLs that arenā€™t serialized, but widgets and plugins often serialize their entries, so itā€™s possible youā€™ll miss some serialized URLs if you just use sed.

Er, yes. Just learned that the hard way. Thanks :wink:

Iā€™m telling ya, once you get wp-cli installed (Itā€™s included in VVV, along with grunt, Node, Composer), itā€™s a handy tool. To search/replace with whatever URL is already in the db, hereā€™s what I use. It finds the existing URL and replaces it across all tables.

wp search-replace `wp option get home` http://local.domain.com

Equivalent to:

wp search-replace http://www.domain.com http://local.domain.com

But Iā€™ll still say the easiest way to migrate dbs is to use WP Migrate DB Pro. Once you get it set up, you can push/pull databases all over the place with a click of a button, so you can really iterate rapidly between environments.

1 Like

Yes, agreed. Iā€™m using WP Migrate Pro right now. Still not had chance to play with wp-cli but I have it installed.

2 Likes

jplew has a promising script based solution for syncing the WP database and uploads/assets.

Iā€™m just starting a new WP project with Roots (delighted when I found it) and am planning to do git deployment for the first time so Iā€™m quite a noob at all this, but it feels good to be doing things like a Grown Up. At the moment jplewā€™s script is my first choice for tackling the DB/assets dev/prod sync question.

2 Likes

This might be an option:

Havenā€™t used it yet, stumbled upon it a while ago.
Should be the same as Migrate DB Pro, but free.

@mjc, thanks for pointing out SyncDB. That script is essentially a much better way of doing what Iā€™ve hacked together with bash scripts + Search-Replace-DB. Assuming it works, it has the potential to finally complete my automated, fully-CLI workflow for syncing whole WordPress websites. I might even be able to use that for my Magento syncs.

@treb0r all fine with wp db migrate pro? weā€™re considering to get the 100 license in order to solve once for all the serialization problem. What about integrating wp db migrate pro with composer, is it the same plugin code which you install from wp packagist? If not, how to integrate the pro version in composer? Thanks

Er, sorry for the extremely late reply, missed this before.

Just for the record, Iā€™m still using WP Migrate DB Pro and it works fantastically well with Bedrock.

I did toy with the idea of adding a Capistrano task to handle DB migrations but Iā€™ve found that it makes a lot of sense to handle the DB separately. Sometimes you just need to update the theme files or the plugins and you donā€™t need to touch the database.

Iā€™m using the wp-cli add-on for WP Migrate DB pro to schedule nightly backups of all of my client sites back to stage. Works great, canā€™t recommend it enough.

The media files add-on is also really useful.

@treb0r
Not sure if this helps but I use wpcli and some aliases:

dbpullP='be cap production wpcli:db:pull'
dbpullS='be cap staging wpcli:db:pull'
dbpushP='be cap production wpcli:db:push'
dbpushS='be cap staging wpcli:db:push'

Iā€™m newish to all of this, why would I need to do more than this? Is it for purposes of automation when you have to manage lots of sites?

edit: the be is for bundle exec

1 Like