Sync and deploy your wordpress website between environments 🔀
MIT License
A bash script that helps you
[!NOTE] For less technical users I recommend to use a plugin instead. For database migrations, I'd recommend WP Migrate. For deployment, I'd recommend good old (S)FTP.
.env.wp-sync-deploy
file):.
├── content # your WordPress content folder (equivalent to the standard wp-content)
│ ├── plugins
│ ├── themes
│ ├── ...
├── core # your WordPress core folder (wp-admin, wp-includes, ...)
├── index.php # main WordPress entry file
└── wp-config.php # your wp-config file
[!TIP] While it's easy to setup the custom directory structure yourself, I'd recommend to use a framework like Bedrock, WPStarter or wordplate. All of these provide amazing convencience features for modern WordPress development.
# CD into your project's root folder
cd /path/to/your/root
# Clone this repo
git clone [email protected]:hirasso/wp-sync-deploy.git
# Make sure the scripts are exectutable
chmod +x ./wp-sync-deploy/*.sh
Alternatively, you can install this script as submodule:
git submodule add [email protected]:hirasso/wp-sync-deploy.git
If you want to clone your main repo and already have wp-sync-deploy as a submodule, use this command:
git clone --recurse-submodules [email protected]:yourname/your-repo.git
Run this script:
./wp-sync-deploy/setup.sh
This will move the required configuration files to your current working directory and remove the .example
part. You should now have these two files in your working directory:
.env.wp-sync-deploy
This file holds all information about your various environments (local, staging, production). Make sure you add .env.wp-sync-deploy
to your .gitignore
file! Otherwise, it's possible that sensitive information makes it into your repo.
VSCode can syntax highlight the env file for you.
wp-sync-deploy.tasks.php
This file is being used to run automated tasks after deployment. You can adjust this file as you wish or delete it if you don't want it to be executed.
wp-sync-deploy performs a few security checks before proceeding with a deploy:
.allow-deployment
exist on the remote environment's web root?So when you are starting, you will need to
.allow-deployment
to your remote web root# sync the database from your production server
./wp-sync-deploy/sync.sh production
# sync the database from your staging server
./wp-sync-deploy/sync.sh staging
# push your local database to your staging server
./wp-sync-deploy/sync.sh staging push
[!NOTE] Syncing your local database is only possible to the staging server by default. If you are sure you know what you are doing, you can also enable syncing to the production server.
# deploy your files to your production server (dry)
./wp-sync-deploy/deploy.sh production
# deploy your files to your staging server (dry)
./wp-sync-deploy/deploy.sh staging
# deploy your files to your production server (non-dry)
./wp-sync-deploy/deploy.sh production run
# deploy your files to your staging server (non-dry)
./wp-sync-deploy/deploy.sh staging run
wp-sync-deploy will automatically run tasks on the target server when you sync or deploy. Modify the wp-sync-deploy.tasks.php
file created by the setup script, to customize which tasks should be executed.
Default tasks defined in the file are:
wp-sync-deploy has a default list of files and directories that will be ignored during a deploy. If you wish to customize this list, you can do so by modifying the file .deployignore.