magento2 – Error switching magento 2 version

The PHP version on your CLI and web server can be different. Put phpinfo();die; directly after the php opening tag to identify the version. If you have recently installed an updated PHP version you may just need to reload NGINX (or whatever you are using for your web server).

Identify the version and determine how that is configured on the server then switch it out for the correct version.