Everyone knows not to do testing in a production environment. Although this is common practice in critical business environments, I can really recommend to do this for your own (personal) servers and websites as well. Of course, there isn't really the need if you have a safe rollback mechanism in place and you can afford a few minutes downtime. But in many cases this is not possible and that's where a testing environment comes in handy. Nowadays it's so simple, fast and cheap to create a testing environment, that I don't see a reason why you shouldn't do it.
Easy: use cloud providers that have a quick and easy way to deploy servers. They allow you to deploy a new server in sometimes less than a minute, with your preferred Linux distribution. After deployment, you can do your tests, make snapshots and do all other kinds of stuff that allows you to try your changes without hurting your production environment. This saves a lot of time. Not only in case everything goes wrong, but also because snapshots allow you to rollback quickly and do another test.
Inexpensive: less than $0.01/hour
Cloud Servers are really inexpensive. If you need a cloud server to test changes to your WordPress site, whether it's in the site, or you're going to upgrade PHP, most of the time it's sufficient to have a server with 1 CPU core, 1 GB RAM and 10 GB disk space. There are several Cloud Server providers where you can deploy those for less than $0.01/hour! Or if you need a bit more memory, for example to test some optimizations that rely on memory (Redis, memcache, MySQL tuning), deploy a 4 GB RAM server for just about $0.03/hour. That means you can test for 5 hours and it will only cost you about $0.05 to $0.15, depending on the chosen configuration.
If you don't need your testing cloud server anymore, you can just remove it and you only pay the hours that you actually used the server. Please note that most providers still bill you the hourly tariff when a cloud server is stopped but still stored on their cloud. They do this because they reserve the resources for you, even when the cloud server is not running. So don't forget to remove the cloud server.
Personally I prefer to use DigitalOcean or Vultr. Their products are more or less the same. Both can provide you with cloud servers in one of their data centers (they have locations in multiple countries), deployment is very quick and they do billing by the hour (with a small discount if you use a server for a full month).
If you like my blog, please use one of my referral links, so I get a bit of DigitalOcean / Vultr credit in return. I use this to test things and make blog articles:
Of course, feel free to find another cloud server provider that suits your needs, or signup without me referral code.