Hey @uberaff, welcome to Roots!
If I understand correctly, you’d like to have a staging site on, say, staging.example.com
with the same code and database as production.
First, you’ll need the IP of the staging server added to hosts/staging under both [staging] and [web].
Next, add your site details to staging/wordpress_sites.yml
. If you’ve already configured it for production you can copy and paste this over. Remember to also modify the vault.yml
file with the name of your site.
site_hosts
creates the nginx server blocks that your staging site will be served at. You could use the IP address of the server here, which means going to http://123.456.789.10
would return your site, however if you have a domain to use you should enter this here. It could be stagingserverforexample.com
or staging.example.com
, as long as you point that domain/subdomain to the IP address of the server.
If you’re following the repository structure from the roots-example-project then you’ll need to keep local_path
and repo_subtree_path
as ../site
& site
. These point Ansible and Git to the root of your site in the repo.
If you’re deploying the main branch to your production server and would like the staging site to be exactly the same, keep branch: master
. If you were setting up an external development server for your team (before the client sees it) then you might consider switching this to a develop branch (or similar).
Other than that the process should be the same between production and staging.
You will want to keep the databases separate from each other so that you can play around in staging without affecting production however before presenting to the client you would probably want to update the staging site to match the production site.
Trellis itself doesn’t cover this but it does make it easy using WP-CLI and SCP/rsync.
If you want staging to match production:
# backing up production to your local copy
ssh web@production.server
cd /srv/www/example.com/current
wp db export # dumps the database to something like `example_production.sql`
exit # or you could open another shell to perform the syncing, deleting the dump after you're finished
cd ~/sites/example.com/site # your local copy of the site
scp web@production.server:/srv/www/example.com/current/example_production.sql . # copies the dump to the folder you're in
rsync -azP web@production.server:/srv/www/example.com/shared/uploads/ web/app/uploads/ # syncs your local uploads folder with the one from production
# syncing staging with your local copy
scp example_production.sql web@staging.server:/srv/www/example.com/current # copies the dump up to the staging site
rsync -azP web/app/uploads/ web@staging.server:/srv/www/example.com/shared/uploads/ # syncs the uploads folder on the staging server with your local copy
ssh web@staging.server
cd /srv/www/example.com/current
wp db reset # then y to confirm # clears the current database
wp import example_production.sql
wp search-replace domain-for-production.com domain-for-staging.com # replaces all references to the domain inside wordpress
( or you could skip copying these down to your local copy by copying the files to /srv/www/example.com/current/web
and using curl
or wget
on the target machine to grab example.com/example_production.sql
or the uploads folder)
Let me know if you have trouble or I’ve misunderstood