I’m using a basic DigitalOcean droplet with the roots trellis/bedrock/sage project. Everything is working well and I’m able to successfully deploy.
The problem I’m having is using wp-cli on my remote server. When I SSH into the server, I switch directories to cd /srv/www/mysite.com/current and attempt to use wp-cli.
I’m getting two errors:
It has me using wp-cli as “root”, which isn’t advised
It asks me for the path to the WP directory
I can run commands, but only if I use format below: sudo -u admin -i -- wp plugin delete soil --path=/srv/www/dianaweymar.com/current/web/wp
I edited wp-cli.yml on the remote server and tried setting path: to the full path from /srv/ (it was already /web/wp) but it didn’t change anything. I also tried setting user: admin to fix the first issue, but again, didn’t change anything.
Is there a quick fix to all this that I’m missing. And, more importantly, do most trellis users normally log into their remote server to run updates using wp-cli?
My main reason for figuring this out is so I can copy my local database to my production database using wp-cli.
This is what I use wp-cli for mostly and it makes it quite easy:
wp db export # exports example_dev.sql to /site folder
scp example_dev.sql web@production:/srv/www/example.com/current
wp db reset # then y to confirm
wp db import example_dev.sql
wp search-replace example.dev example.com # add --dry-run to see what would change before applying
Logging in (or switching users) to web did the trick. It also solved the--path issue!
Regarding the database sync, that looks good. I was curious what the normal practices were as I couldn’t find it mentioned anywhere else. I wasn’t aware of the scp command either - much better than committing the db to git.
One more question regarding doing a search-replace on urls:
In wp-db migrate, it runs two URL replacement functions:
from local: /srv/www/example.com/current/web
to remote: /srv/www/example.com/releases/20160201064514/web
As far as I know the steps for WP-CLI should do the same as wp-db migrate.
I’m not sure why you would need to change the path of the site from local to remote though; there is a new release folder created each time you deploy but deploying with Trellis will symlink this new folder to the /current folder once the deploy is finished and so you can leave it as /src/www/example.com/current/web
This is partly because everybody does it differently. It sounds like wp-db migrate does the same job as WP-CLI here and so if you’re used to it I would stick with it. Another option mentioned on the forums is to use wp migrate db pro although this plugin costs money.