What is the correct way to set up a staging server and use github for version control?

I have Wordpress site at /var/www/contoso/html (contoso.com) running on a CentOS 8 server. I would like to run a new theme and make some frontend changes to it to make it match the look and feel of the old theme. I imagine that using a staging instance is the way to go.

Is the proper approach to copy site files to /var/www/contoso-staging/html (dev.contoso.com) and use a copy of the database? Or would it be possible to simply create a read-only database user and use the production database?

Also, I'd like to use version control for this. Would I create a GitHub repo for the production site and another for the staging site? Once the changes are finalized in staging, what would be the proper way to copy them over to live site?

If you have any suggestions outside of this, or if I am not on the right track, please feel free to offer your thoughts.

Thank you.

Topic github staging themes Wordpress

Category Web


Usually people don't create a repo for their entire site. Instead, they typically will create a repo for each theme and plugin.

So, you'll have a staging site where you can edit your theme (or child theme) files and keep those all in a repo. Once everything looks good on staging, you can then push from the repo to the live site. The trickiest part is usually dealing with the database, because there are many places WP will set the URL in the database, and some of these are serialized, meaning if you do a simple search and replace, you'll end up breaking the site. But if you're not doing much data work that has to be pushed back and forth between sites, usually the file push to git and then just pushing from git to both your staging site and your live site is typically a good way to version your code and test things before they go live.

You can get even more fancy and use Github Actions to automatically deploy to your live site, but it all depends on whether you need that level of automation or not.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.