How to run a different version of PHP for only one folder

darkus

Verified User
Joined
Dec 15, 2005
Messages
151
I have system with PHP 8.3 and PHP 7.1 installed. For now, my one and only domain is set to run on PHP 7.1, however for a single folder I want to run php 8.3

I found some old threads mentioning to do this:

Code:
<FilesMatch "\.(php|php4|php5|php3|phtml)$">
SetHandler "proxy:unix:/usr/local/php83/sockets/admin.sock|fcgi://localhost"
</FilesMatch>

Which does not work. I think it has to do with PHP-FPM. While I have php-fpm71, i do nothave php-fpm83 as far as i can tell (no config files for it found, probably because ive never actually deployed a domain usig it yet). PHP 8.3 is for sure installed on the system, becuase logged in throgh ssh if i do a simple php -v i get 8.3

I changed the above to 7.1 just to test and it does work again. Ive alternativly found suggetions to do
SetHandler application/x-httpd-alt-php83
SetHandler application/x-httpd-ea-php83

and neither of those work either.

Does anyone have an idea how to overcome this? It seems like the very top was the closest I could get however I got blunted by the FPM issue
 
Ok it looks like while admin.sock exists for my 7.1 version, the file does not even exist for my 8.3 version, which is why that fails. But since i dont have any domainactually running 8.3, I find myself in a catch 22...
 
Possible solution:

Create a subdomain, for example, test.domain.com and set that subdomain to php 8.3 and that will do the job perfectly, leaving your main site domain.com to function with php 7.1

Edit, Solution the way you may be looking for:

If you want the subfolder variant to work, the only way i've managed to get it to work is to set up a subdomain, test.domain.com and make the root of that subdomain public_html/test .

Set that subdomain to php 8.3 (Option is on the subdomain tab) and leave main site as php 7.1

Check the socket file exists now in /usr/local/php83/sockets

Then create the .htaccess file in the public_html/test folder

PHP:
<FilesMatch \.php$>
    SetHandler "proxy:unix:/usr/local/php83/sockets/admin.sock|fcgi://localhost"
</FilesMatch>

If you don't want the folder being accessed by the subdomain, delete the subdomain A record in the DNS and the folder will still operate, minus subdomain access.

1765702018593.png
 
Last edited:
Possible solution:

Create a subdomain, for example, test.domain.com and set that subdomain to php 8.3 and that will do the job perfectly, leaving your main site domain.com to function with php 7.1

Edit, Solution the way you may be looking for:

If you want the subfolder variant to work, the only way i've managed to get it to work is to set up a subdomain, test.domain.com and make the root of that subdomain public_html/test .

Set that subdomain to php 8.3 (Option is on the subdomain tab) and leave main site as php 7.1

Check the socket file exists now in /usr/local/php83/sockets

Then create the .htaccess file in the public_html/test folder

PHP:
<FilesMatch \.php$>
    SetHandler "proxy:unix:/usr/local/php83/sockets/admin.sock|fcgi://localhost"
</FilesMatch>

If you don't want the folder being accessed by the subdomain, delete the subdomain A record in the DNS and the folder will still operate, minus subdomain access.

View attachment 9541


I love the idea, sounds reasonable in theory. Before i try it, do you think its possible to have it just run without php-fpm? that folder is just a small test project that i would only visit and dont need any kind of performance benefits or caching
 
Back
Top