I am using Ubuntu 16.04.
I have several virtualhosts, and I need to run different PHP versions. I have php-fpm
and FastCgi
installed, but how can I configure it?
I am using Ubuntu 16.04.
I have several virtualhosts, and I need to run different PHP versions. I have php-fpm
and FastCgi
installed, but how can I configure it?
Maybe not the response that you're waiting for, but it gets painful to manage several php versions in your machine.
I've found that the best approach is to have a newer php version (php7+) as primary, and if I need something older or another specific version, I use a container with apache/php from here or use this as base image and modify it as necessary, it has great instructions to do that.
In the case that I need an older php version (unsupported so be careful), I can just build from an older OS version with support for that particular version.
The advantages of this approach are, first, that you don't mess up your machine with lots of packages and dependencies. Second, you don't pollute your php install with all the dependencies and packages that eventually will conflict with each other due to version-incompatibility. Finally, and super importantly, dockerizing apps will give you a replicable recipe for your production environment.
Even if you don't choose this as your approach, take a look at docker. It will make your like easier and it's "the thing" used in development nowadays.
With nginx, all you have to do is use sockets via proxy_pass
:
server{
(...)
location ~ ^/index\.php(/|$) {
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
}
}
With apache you need to use proxy
:
<FilesMatch "\.php$">
SetHandler "proxy:unix:/var/run/php/php7.2-fpm.sock|fcgi://localhost/"
</FilesMatch>
This way, you can use different sockets (each for different version of PHP) by configuring them within each Virtual Host