Because sometimes you are just trying to sync your codebase and database from a local host to a remote one--no complex deployment strategies here!
In my case, I love developing with Bedrock and Laravel Valet and I haven't found a simple deployment strategy for my current setup. So, this is my simple workflow:
- Make sure you have set up remote directories.
LOCAL
- Install Bedrock to your dir of choice (in this case to "bedrock-app"):
$ composer create-project roots/bedrock bedrock-app
- Configure Bedrock as needed. Pay attention to your local & remote paths.
- Create
bedrock-app/_db
directory. - Copy this gist to your project's root directory for easy access. (ex. bedrock-app/_SYNC.mk)
- Configure the
_SYNC.mk
&_SR_DB.mk
files to match your project needs. - When you're ready to sync to remote,
cd
to your project's root directory and run:
$ make -f _SYNC.mk
- Hit 'y' to run the makefile.
- If everything worked, it will open a new connection to the remote host and
cd
you into the project's dir.
REMOTE
- Make sure your DB credentials in the remote .env file have been configured.
- Reset and/or import the synced db:
$ wp db reset $ wp db import _db/DB_NAME_HERE
- Make sure
_SR_DB.mk
has been configured with old and new URLs. - Run this to search & replace URLs in the remote db:
$ make -f _SR_DB.mk
WARNING: LINES 78 & 98 have a --delete
flag, which means it will delete everything on the remote host and mirror the local files. Remove the flag if you don't need it.
- 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 script exports to:
_db/dev-DATABASE_NAME-YYYY-MM-DD-HHMMSS.sql
. To change this, configure lines 21, 43, 44. - If not using Elementor, remove line 76 in
_SYNC.mk
and lines 13 and 14 in_SR_DB.mk
.
If you only need to run a specific step in the _SYNC.mk
script, run:
$ make -f _SYNC.mk 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.