Set up a staging environment of your WordPress website with Combell

Note: This tutorial is specific for Combell hosting (my favourite Belgian hosting company), but you can certainly take away something here if you are using another hosting provider.


According to Combell’s documentation there isn’t a button to set up a staging website, like some other hosts do (Siteground for example). Despite this, I still love Combell, and as a developer it doesn’t hurt to dive into some bash scripting from time to time. So, here we go!

In this tutorial I will set up a staging site for my webshop: shop.bdwm.be, so make sure to replace any occurrences of shop.bdwm.be with your own domain.

1. Set up a subsite and a database

Combell doesn’t allow us to create a new subsite and database via SSH, so we’ll need to take care of these 2 steps manually. Luckily, it’s something we only need to do once.

  1. create a new subsite: shop.staging.bdwm.be (replace with your own staging domain)
  2. create a new database

2. Create your script

live_domain='shop.bdwm.be'
stag_domain='shop.staging.bdwm.be'

live_path="$HOME/subsites/shop.bdwm.be"
stag_path="$HOME/subsites/shop.staging.bdwm.be"

db_name_stag='ID123456_shopstaging'
db_user_stag='ID123456_shopstaging'
db_pass_stag='stagpass123'
db_host_stag='ID123456_shopstaging.db.webhosting.be'

db_name_live='ID123456_shop'
db_user_live='ID123456_shop'
db_pass_live='livepass123'
db_host_live='ID123456_shop.db.webhosting.be'

# rsync live files to staging
rsync -avz --delete $live_path/ $stag_path/

# Create dump of live database
mysqldump --user=$db_user_live --password=$db_pass_live --host=$db_host_live $db_name_live > ~/tmp/live_db_dump.sql

# Import dump into staging database
mysql --user=$db_user_stag --password=$db_pass_stag --host=$db_host_stag $db_name_stag < ~/tmp/live_db_dump.sql

# remove temporary dump file
rm ~/tmp/live_db_dump.sql

# update wp-config
wp config set DB_NAME $db_name_stag --path=$stag_path
wp config set DB_USER $db_user_stag --path=$stag_path
wp config set DB_PASSWORD $db_pass_stag --path=$stag_path
wp config set DB_HOST $db_host_stag --path=$stag_path

# find and replace live domain with staging domain in database
wp search-replace $live_domain $stag_domain --path=$stag_path

# clear cache
wp cache flush --path=$stag_path

3. (Optional) change some settings

Depending on your setup, you might want to disable some plugins or switch your woocommerce shop to test mode. This will be highly specific for your case, but for my website I perform these additional actions at the and of the script.

# disable problematic/unnecessary plugins
wp plugin deactivate jetpack --path=$stag_path
wp plugin deactivate wordfence --path=$stag_path
wp plugin deactivate wordpress-seo --path=$stag_path

# set stripe test mode to yes
wp option get woocommerce_stripe_settings --format=json --path=$stag_path | jq '.testmode = "yes"' | wp option update woocommerce_stripe_settings --format=json --path=$stag_path

4. Save your script and run it whenever you need to sync

Save your script as staging-script.sh and save it to your combell server.

Make sure it’s executable by running this command:

chmod +x staging-script.sh

Now, run the script:

~/staging-script.sh

That’s all! Next time you need to pull in the live database and files to your staging, simply execute this last command again.