As @Abilogos has mentioned in his answer, you can have multiple versions of php using update-alternatives
and in cli, version which is set to default will work with php
command but when it comes to run a specific version for a website with Apache/Nginx, it get's difficult and I also faced this thing recently when I wanted to make my code PHP 8 compatible parallely without hampering the existing working code and finally I was able to get it what I needed to make all this thing work.
Here is what I did on Fedora 33
Step 1. Installed PHP 8.0 as default version and using Remi repo, I've installed other PHP versions as well (5.6, 7.0, 7.1, 7.2, 7.3 & 7.4)
Step 2. I checked to update-alternatives
to change the PHP version from 8.0 to 7.4 but there were not entry in it. So, I installed all these in update-alternatives
cp /usr/bin/php /usr/bin/php80
update-alternatives --install /usr/bin/php php /usr/bin/php80 0
update-alternatives --install /usr/bin/php php /opt/remi/php74/root/usr/bin/php 1
update-alternatives --install /usr/bin/php php /opt/remi/php73/root/usr/bin/php 2
Step 3. Now, it is very easy to change PHP version in cli at any time easily. Example, when your application have dependency on some libraries but they are PHP 8 compatible and you want to change the default PHP version to run the composer install
Step 4. Now, to configure website1 to run on PHP 8 and website2 to run on PHP 7.4, we need two PHP-FPM configured and running on different ports.
Change default PHP-FPM port
vim /etc/php-fpm.d/www.conf
;listen = /run/php-fpm/www.sock
listen = 9001
Similarly, change PHP-FPM 7.4 port
vim /etc/opt/remi/php74/php-fpm.d/www.conf
;listen = /run/php-fpm/www.sock
listen = 9002
Start/Restart PHP-FPM services
systemctl start php-fpm
systemctl start php74-php-fpm
Step 5. Change vhost configuration file to use different version of PHP for website1 and website2
vim /etc/httpd/conf.d/website1.conf
<FilesMatch \.php$>
# PHP 8.0
SetHandler "proxy:fcgi://127.0.0.1:9001"
</FilesMatch>
vim /etc/httpd/conf.d/website2.conf
<FilesMatch \.php$>
# PHP 7.4
SetHandler "proxy:fcgi://127.0.0.1:9002"
</FilesMatch>
Restart Apache/Nginx
systemctl restart httpd
And we're done