Different PHP version, directory level

SYSTEM INFORMATION
OS type and version AlmaLinux 9.2
Webmin version 2.021
Virtualmin version 7.7 Pro

I’m wondering how to specify the PHP version to use in a specific directory of a website.

Also, is it possible to be able to use .htaccess to control which PHP version to use instead of Virtualmin? I’ve done it before but it doesn’t seem to work under Virtualmin.

So what - different versions of PHP on the same website?

Yes.

domain.com/ → 8.3
domain.com/folder1/ → php 8.2

.htaccess would be the preferred solution, but whatever works is what I’ll have to use.

If you use php in fcgi mode rather than fpm you can set the directory version of php from within virtualmin. It’s in the php options of the domain

How do I enable fcgi overall?

Go to the domain hit php options and change it there … you can also set the directory versions there also . You may have to reload the vmin page in order to see the directory bit … tbf it’s been a while since i did it.
Domain->server settings->php options

Are you using apache ?

Yes, via httpd folders (vs apache folders).

install mod_fcgid from your package manager, I don’t use enterprise linux (alma, rocky etc) but I would think the command is

yum install mod_fastcgi

No. Don’t do that.

First, mod_fastcgi is not fcgid, and second, you can’t use fcgid execution mode safely in AlmaLinux 9 (or 8). We no longer recompile Apache for suexec docroot to be in /home.

fcgid execution mode is not an option for this system.

1 Like

Thanks for pointing that out

Ubuntu and Debian can use fcgid because they have a suexec-custom package that allows arbitrary suexec docroot. But, FPM is still the preferred/recommended execution mode.

1 Like

So any advice on how to have different PHP versions running based on the directory (folder/url) of the same domain?

Use Ubuntu 22.04 or Debian 12.

@Jamie and I were discussing it the past … I mean, making PHP-FPM to work on directory basis. I remember it was possible, and I think this is the way to go for the future, so we could with a light heart drop all other PHP execution modes, and just have PHP enabled/disable mode instead, to make it nice and simple…

So I need to do a full reinstall of a different flavor of Linux in order to gain this ability?

Does this mean that there are no plans to make it possible for an .htaccess file to change it?

There are plans, but it’s not going to happen within the next few weeks. Our plan is to eventually deprecate all other execution modes, as they’re all worse than FPM on most fronts (performance, memory, security, ease-of-use/maintenance/troubleshooting, etc.).

Generally, it’s a good practice to consolidate your apps as much as possible to use the same current version of PHP. (Though I get that sometimes that’s not feasible, due to third party proprietary apps or whatever taking a long time to update.)

In the meantime, you’d need to do it some other way; either different domains for each app that needs a different PHP version, or manually configure it.

But, you may want to just try your apps (or read the docs for the app, if you didn’t write them yourself) with one version of PHP and see how much needs to change. It’s usually not a lot when going from an old version to a newer one. Going from PHP 7 to PHP 8 is usually very easy, and there are guides from the PHP devs about making it work. Sometimes there are options you can change in your PHP configuration to make old behavior available in new versions. That’s a better idea than running a bunch of PHP versions, usually.

1 Like

You mean manually configure which version is used in a directory? HOW? That’s what I’m wanting to know how to do!

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.