Skip to main content
  1. All Posts/


Tools Open Source Sync WordPress

Sync WP Site Makefile Recipe

A quick recipe to sync your codebase and database from a local host to a remote one.

If you love developing with Bedrock and Laravel Valet and haven’t found a simple deployment strategy, follow along!


  1. Make sure you have set up remote directory to sync with local.
  2. Install Bedrock to your directory of choice (in this case to “bedrock-app”):

    $ composer create-project roots/bedrock bedrock-app
  3. Configure Bedrock as needed. Pay attention to your local & remote paths.
  4. Clone or download this repo to a directory inside your app. (ex. bedrock-app/wp-sync/

    $ git clone
  5. Configure the & files to match your project needs.
  6. When you’re ready to sync to remote, cd to your project’s directory and run:

    $ make -f wp-sync/
  7. Double-check the paths and press y to run the makefile. Press any other key to exit.
  8. If everything worked, it will open a new connection to the remote host and cd you into the project’s directory.
  9. Make sure your DB credentials in the remote .env (or wp-config.php) file have been configured.
  10. Reset and/or import the synced db:

    $ wp db reset
    <pre>$ wp db reset && wp db import db/DB_NAME_HERE.sql</pre>
  11. Make sure has been configured with old and new URLs.
  12. Run this to search & replace URLs in the remote database:

    $ make -f wp-sync/

Assumptions & other notes

  • Both local and remote hosts have Bash shell and WP-CLI installed.
  • SSH connection to remote host is set up and working.
  • If SSH key has passphrase, it will need to be entered multiple times. 🤷
  • The makefile can be called from anywhere–the script will detect where it’s located and use relative paths to run the commands. However, when you call it, make sure you add the path relative to where you are located. For example,
    • If you are in ~/dev/sites/
    • and the app is in ~/dev/sites/bedrock-app/
    • then run:
    <pre> $ make -f bedrock-app/wp-sync/</pre>
  • The recipe exports the database to: db/dev-DATABASE_NAME-YYYY-MM-DD-HHMMSS.sql. To change the path or filename, update lines 33, 55, 56.
  • If you would like to completely mirror both local and remote directories, you could pass a –delete flag in lines 93 & 114. Be very careful with this flag. If paths are configured incorrectly, this could delete files not meant to be deleted.

If you only need to run a specific step in the script, run:

$ make -f wp-sync/ step_name_here

Available steps are:

  • rsync_code: Syncs the codebase directory.
  • dump_db: Exports the local db.
  • rsync_db: Syncs the database directory.
  • ssh_remote: SSH into the remote host.