Yes you can use different PHP versions per vhost. But it's quite fiddly to setup (at least for me it was). Have a look at mod_proxy_fcgi and ProxyPassMatch.
I once managed to set this up in Docker (Dockerfile). Natively I guess it must go along the lines of the following Apache confs.
drupal6.com.conf
Listen 80
<VirtualHost *:80>
ServerName drupal6.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/php56
ErrorLog ${APACHE_LOG_DIR}/php56error.log
CustomLog ${APACHE_LOG_DIR}/php56access.log combined
ProxyPassMatch "^/(.*\.php(/.*)?)$" "unix:/var/run/php/php5.6-fpm.sock|fcgi://localhost/var/www/php56"
<Directory "/var/www/php56">
Order allow,deny
Allow from all
AllowOverride FileInfo All
Require all granted
</Directory>
</VirtualHost>
drupal7.com.conf
Listen 80
<VirtualHost *:80>
ServerName drupal7.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/php72
ErrorLog ${APACHE_LOG_DIR}/php72error.log
CustomLog ${APACHE_LOG_DIR}/php72access.log combined
ProxyPassMatch "^/(.*\.php(/.*)?)$" "unix:/var/run/php/php7.1-fpm.sock|fcgi://localhost/var/www/php72"
<Directory "/var/www/php72">
Order allow,deny
Allow from all
AllowOverride FileInfo All
Require all granted
</Directory>
</VirtualHost>
For Nginx take the following approach as starting point (source).
$ git clone https://gist.github.com/2fca8bfdc5004bade15bac84b9ab73e7.git test/multiphp
$ docker build -t nginx-multiphp test/multiphp
$ docker run -p 8856:8856 -p 8871:8871 --rm -P nginx-multiphp
- In your browser visit:
http://localhost:8856 for PHP56 and http://localhost:8871 for PHP71 accordingly.
- Happy happy