Syncing Bedrock-based WordPress environments with WP-CLI aliases and rsync
.
Create a new scripts/
directory in your Bedrock directory (site/
) and place the sync script inside of there.
Make sure that sync.sh
is executable (chmod u+x sync.sh
).
WP-CLI must be installed on all environments (local and remote).
Edit the variables at the top of sync.sh
to match the settings for your environments:
DEVDIR
— Local path to uploads directoryDEVSITE
— Local dev URLPRODDIR
—user@hostname:/path/to/uploads/
PRODSITE
— Production URLSTAGDIR
—user@hostname:/path/to/uploads/
STAGSITE
— Staging URL
The Kinsta version of the script is slightly different:
REMOTEDIR
—user@hostname:/www/example_123/public/shared/uploads/
PRODPORT
— Production portSTAGPORT
— Staging port
WP-CLI aliases must be properly setup in order for the sync script to work. Open wp-cli.yml
and setup the aliases for your environments.
# site/wp-cli.yml
path: web/wp
@development:
ssh: [email protected]/srv/www/example.com/current
@staging:
ssh: [email protected]/srv/www/example.com/current
@production:
ssh: [email protected]/srv/www/example.com/current
Test the aliases to make sure they're working:
$ wp @development
$ wp @staging
$ wp @production
# site/wp-cli.yml
path: web/wp
@development:
ssh: [email protected]/srv/www/example.com/current
@staging:
ssh: [email protected]:54321/www/example_123/public/current/web
@production:
ssh: [email protected]:12345/www/example_123/public/current/web
Open .gitignore
in your Bedrock directory (site/
) and add the following:
# WP-CLI
*_development*.sql
When you sync down to your local development environment a database backup is performed with wp db export
. This helps you safely recover your database if you accidentally sync, and by making this modification to .gitignore
you're ensuring that your local database export doesn't accidentally get commited to your git repository.
Uncomment the lines near the end of the script if you'd like to enable the Slack notification for when the sync directory is up or horizontal.
Make sure to create a new incoming webhook and updating the URL in the script, as well as the channel.
If your local development environment is a VM, don't run the sync script from inside of the VM — run it on your host machine.
Navigate to the site/scripts/
directory to use the sync script.
Possible sync directions:
# Sync production down to development
$ ./sync.sh production development
# Sync staging down to development
$ ./sync.sh staging development
# Sync development up to producton
$ ./sync.sh development production
# Sync development up to staging
$ ./sync.sh development staging
# Sync production to staging
$ ./sync.sh production staging
# Sync staging to production
$ ./sync.sh staging production
The --skip-db
flag can be passed to skip syncing the database.
The --skip-assets
flag can be passed to skip syncing assets.
# Sync production down to development
$ ./sync.sh --skip-db production development
# Sync production down to development
$ ./sync.sh --skip-assets production development
The --local
flag can be passed to skip using WP-CLI aliases for development. This means that you can use the sync script on a local development setup such as Valet.
# Sync production down to development
$ ./sync.sh --local production development
Make sure that your local development setup is up and running.
Make sure that you're able to successfully connect with a SSH connection with the same details configured for the same WP-CLI alias.
If your SSH connection doesn't fail, make sure WordPress is first already installed.
Shoot me an email with any issues you run into.
You can re-download the latest version by visiting https://roots.io/product-links/.