Not knowing your hosting plan.
Most shared hosting accounts now have a multiphp option in cpanel where you can just select what version you wish provided the host provides it.
Most hosts allow up to php7.4.
As far as mysql goes usually you would need to request a upgrade from the host for a shared hosting account.

I have zero experience with a virtual machine setup.
I have never seen the advantage for myself.
If I wish to have a local test site I usually use wamp or xampp.installed on my pc.
Then I can play with testing multiple versions of php,apache and mysql combinations.


Blue Man Group
There is no such thing as stupid questions. Just stupid answers