1

I've been looking at PHP-FPM recently but I've failed find examples that show more than one version of php being employed to serve different files on the same host instance. Is it possible?

Example person
  • 3,198
  • 3
  • 18
  • 45
Richard
  • 11
  • 1

1 Answers1

0

Yes, you can run multiple versions of PHP (PHP-FPM is very possible too) on the same virtual host. But, you have to name the extensions of the files of each of the versions.

You would need to run each of the the PHP-FPM versions on diffrent ports, by adding different ports for the listen directive in each of the www.conf: For example, listen 127.0.0.1:9000 for one of the php versions, and listen 127.0.0.1:1234

For example, you would want to name the file extension of the files which want to run PHP 7.4 as .php74, and for another example, you would want to name the file extension as php80 for the file which want to run PHP 8.0.

How can I acheive this:

Install php-fpm, and then inside www.conf for php 7.4 for example, you should set security_limit_extensions as security.limit_extensions = .php74.

And for php-8.0's php-fpm, you would want to set it to .php80.

And finally, if you are using Apache, you can add this to use the appropriate version for the appropriate files only (I am not a Nginx user, so, good luck finding info about that):

<FilesMatch "\.php74$">
    SetHandler  "proxy:fcgi://localhost:9000"
</FilesMatch>

For PHP 8.0 now:

<FilesMatch "\.php80$">
    SetHandler  "proxy:fcgi://localhost:9000"
</FilesMatch>

See PHP-FPM's manual, and Apache's documentation about mod_proxy_fcgi.

Example person
  • 3,198
  • 3
  • 18
  • 45