Question Different PHP version for folders

Thomas Oryon

Regular Pleskian
Hello Support,

We have plesk in both Linux & Windows server. We can able to change the PHP version for each website. Whether is it possible to have different PHP version for each folders?

Awaiting your reply.
 
Hi, @Thomas Oryon . No, it's not possible to configure a different PHP version on a per directory-basis. However, if you provide more details on the context of your question and an example of your end goal, we can try to suggest an alternative.
 
Hi, @Thomas Oryon ,
If this can help I do exactly this with some .htaccess magic.
Context:
1. create a subdomain for the domain, just to select the php handler your want to use in your folder.
2. reroute the handler from that subdomain in a .htaccess in the folder.

Here under an example of a folder where I wanted another php handler (handler has to exist in your Plesk/System) than the one that is defined for the website.

#This WORKS! I replace the SetHandler with a line from another hosting with php I want
#Add this at the beginning of your .htaccess
RemoveHandler .php
<Files ~ (\.php)>
SetHandler None
SetHandler proxy:unix:///var/www/vhosts/system/<existing subdomain.yourdomain.tld with handler you want>/php-fpm.sock|fcgi://127.0.0.1:9000
Options +ExecCGI
allow from all
</Files>
 
Hi Support Team @Sebahat.hadzhi ,

Thank you for your update.

To clarify my requirement, I have a domain name testing.com and the main domain is currently assigned to PHP 8.3.

I have now created a folder under this domain named sampletest, for example:

testing.com/sampletest/

I would like to know whether it is possible to configure this specific folder to use PHP 8.2, while the main domain testing.com continues to use PHP 8.3.

Please confirm if per-folder or per-directory PHP version configuration is supported, or if there is any alternative method to achieve this.

Thank you.
 
Indeed @Thomas Oryon, exactly what I did:

1. make a subdomain php82.testing.com, with PHP 8.2 as handler, just to be able to reference it in your /sampletest/ .htaccess file. Or use another domain you have that is on PHP 8.2 eg? testing2.com
2. make an .htaccess file in your directory /sampletest/ (so /sampletest/.htaccess) and put the apache directives here under (*) as FIRST in you .htaccess

#This WORKS! I replace the SetHandler with a line from another hosting with php I want
#Add this at the beginning of your .htaccess
RemoveHandler .php
<Files ~ (\.php)>
SetHandler None
SetHandler proxy:unix:///var/www/vhosts/system/php82.testing.com/php-fpm.sock|fcgi://127.0.0.1:9000
Options +ExecCGI
allow from all
</Files>
 
@Thomas Oryon ,
I am not on Plesk Windows Server, sorry.
I did asked my friend "Claude" for a Windows version of my Plesk 'hack', I post it here 'as is', all your responsability :)

Check attached files (zip):
Claude prompt
Claude answer
 

Attachments

  • Claude.zip
    2.6 KB · Views: 1
Back
Top