WordOps is a popular framework to setup and manage WordPress infrastructure, forked from EasyEngine in 2018 when EasyEngine v4 changed their architecture to use Docker containers.
This is a quick guide to setting up a development copy of your live WordPress site which can be useful if you’re working on a redesign or testing new themes.
If you’re not familiar with the WordPress CLI (WP), it does some magic behind the scenes to extract the database connection details from wp-config.php, so as long as we’re in the directory of a WordPress installation it will figure out what to do.
1. First, we’ll create the new site (dev.mysite.com) as a WordPress site with Let’s Encrypt enabled
sudo wo site create dev.mysite.com --wp --le
2. Next, we’ll cleanup the default content on the newly created dev site and copy the files from the production site
sudo rm -rf /var/www/dev.mysite.com/htdocs/* cd /var/www/mysite.com/htdocs sudo cp -a * /var/www/dev.mysite.com/htdocs
3. Now we can use the WP CLI to export the database from the production site and import it to the dev site.
sudo -u www-data -H wp db export ~/mysite.com.sql --yes cd /var/www/dev.mysite.com/htdocs sudo -u www-data -H wp db clean --yes sudo -u www-data -H wp db import ~/mysite.com.sql --yes rm ~/mysite.com.sql
4. Finally use WP CLI to update the WordPress URLs on the dev site
sudo -u www-data wp option update home 'https://dev.mysite.com' sudo -u www-data wp option update siteurl 'https://dev.mysite.com'
The dev copy of your site should now be available. Depending on the nature of the site it could be sensible to password protect the site or restrict traffic to the dev site by IP address.
Restricting access by IP address
Open the nginx configuration for the new site:
sudo wo site edit dev.mysite.com
Then before the closing brace add:
allow <Your IP>; deny all;
Save the changes to the file and check nginx reloads correctly, access to the site should now be restricted to your IP address.
Pushing changes back to production
You can promote your dev site to production by following the instructions the other way around.