Well this one is simple, just use the php prefix and brackets for the packages you want. Here's a one liner that should cover most of your needs:
sudo apt install php8.0-{fpm,curl,mbstring,pdo,zip,gd,mysql,imap,xml,yaml,common,cli,opcache,readline}
And if you want an older version of PHP, just replace php8.0
with say php7.4
. By default they will run as sockets under systemd so you can have multiple versions running at the same time. Especially if you use nginx with virtual hosts, see this example for instance:
location ~ \.php$ {
include conf.d/fastcgi-php.vhost;
fastcgi_pass unix:/run/php/php7.4-fpm.sock;
}
This let you use different versions of PHP for different sites on your server, perfect if you don't fully support PHP8 yet.