Installing two versions of PHP-FMP?

Francis Daly francis at
Tue Oct 11 22:34:43 UTC 2022

On Wed, Oct 05, 2022 at 12:08:34AM +0200, Gilles Ganault wrote:

Hi there,

> I only have shallow experience with nginx.
> To migrate an old php5-based application to the latest release which expects
> php7, I'd like to install both versions of PHP-FPM in one nginx server.

php (with php-fpm) is independent of nginx; so the way to install one
or more versions of php is "whatever your operating system wants".

So do that, to end up with (probably) one tcp port listener (or unix
domain socket) for the php5 fastcgi server, plus one for the php7 fastcgi
server. ("fpm" = "fastcgi", in this context.)

> Although I read elsewhere it's a mistake to install the php package instead
> of php-fpm because the former also installs Apacheā€¦ this is what this
> document <>

This, and the link in the parallel reply, show how to run one nginx
process, configured to run two server{} blocks (which means "two host
names"); and one server{} only uses php5 and the other only uses php7.

Depending on the applications involved, that might be the simplest way
to deploy them.

However, there is no reason not to use one server{} block, provided that
you have a way of knowing which requests should go to each fastcgi server.

> So, what's the recommended way to set things up so that nginx can support
> both interpreters and manage two versions of a web app in their respective
> directory?

Within the server{}, each incoming request is handled in one
location{}. Make sure that requests that should be handled by php5 are
handled in a location that does "fastcgi_pass" to the php5 server; and
the other requests are handled in a location that does "fastcgi_pass"
to the php7 server.

That could be something like

	location ~ ^/app5/.*\.php {
		fastcgi_pass unix:/tmp/php5.sock;
	location ~ \.php {
		fastcgi_pass unix:/tmp/php7.sock;

but the extra details for how each application is installed and what it
expects, will matter.

(And that config fragment would need extra supporting config, in order
to be useful.)

Good luck with it,

Francis Daly        francis at

More information about the nginx mailing list