A simple solution to change between PHP versions without getting a headache!
You just need to run the following version to download or update to the latest version:
curl -fsSL https://raw.githubusercontent.com/kaiopiola/php-switcher/main/install.sh | sh
You only need to run the command with the version you want as a parameter, like below:
phpswitcher 7.4
Check LICENCE file for more information.