Different php versions on different directories of same domain? Is it possible?

evathias

Verified User
Joined
Mar 18, 2019
Messages
21
Dear all,

I have two different directories on a domain:

www.mydomain.com/store (needs php 5.6) and
www.mydomain.com/newstore (needs php > 7.x since last woocommerce update)

Currently, I am migrating the store to newstore. Clients still use the old store.

Is there a way to run different php versions on these two directories of the same domain (until I finish the migration) ?

Thank you for your time.

Kind Regards
Elias
 
Yes, it's possible to do this using .htaccess, but the content depends on the PHP mode used.

Even on boxes with CloudLinux - it's possible to use CloudLinux PHP version per-directory.
 
Thx, unfortunatelly not working as expected (or am I missing something?).

Litespeed +lsapi + CL.

For example: user in PHP Selector have PHP 7.4 - everything is ok.

In htaccess set up: SetHandler application/x-lsphp71

yea, it's working, it load 7.1 BUT (!!!) there are missing settings from phpselector from this 7.1 version. For example: missing many modules (almost empty php) mysqli etc. so user can't use this version ;(

I compared two phpinfo and

Configuration File (php.ini) Path /opt/alt/php71/etc
Loaded Configuration File /opt/alt/php71/etc/php.ini
Scan this dir for additional .ini files /opt/alt/php71/link/conf
Additional .ini files parsed /opt/alt/php71/link/conf/default.ini


Configuration File (php.ini) Path /opt/alt/php74/etc
Loaded Configuration File /opt/alt/php74/etc/php.ini
Scan this dir for additional .ini files /opt/alt/php74/link/conf
Additional .ini files parsed /opt/alt/php74/link/conf/alt_php.ini

Problem is in "Additional .ini files parsed" - I don't know why?
 
They're not controlled in PHP selector, as PHP selector is per-user. Extensions for any PHP versions can be enabled globally (also documented at CL).
 

So we only need to put this to .htaccess file? An option inside directadmin would be much easier for clients who wants to use different PHP version on add-on domains with CloudLinux.

<FilesMatch "\.(php4|php5|php3|php2|php|phtml)$"> SetHandler application/x-lsphp71 </FilesMatch>
 
I know that "per user" and that exactly what I want: in this example: PHP 7.1 with THIS USER SETTINGS from 7.1 (7.4 is default but 7.1 and other versions have user settings saved) but i get 7.1 with no settings ;) Strange.
 
I know that "per user" and that exactly what I want: in this example: PHP 7.1 with THIS USER SETTINGS from 7.1 (7.4 is default but 7.1 and other versions have user settings saved) but i get 7.1 with no settings ;) Strange.

What I'm saying - you're not selecting user modules at all with this version :) It's a different version, just configure your global (default) PHP modules for those, and you'll have preferred modules set.
 
Yes, but it's not that same ;( It's not what user select, it's one global config for everyone who use this "htaccess trick" ;( it's shame that you cant use own config for this ;(

anyway thanks. (y)
 
@Zhenyapan Unfortunatelly It's not working like that ;) Read my first post in this thread ;) When you use htaccess you don't have this own modules config for other versions.
 
@Zhenyapan Unfortunatelly It's not working like that ;) Read my first post in this thread ;) When you use htaccess you don't have this own modules config for other versions.
Let me understand totally - when You configure modules by shown on my screen way for PHP-A and activate PHP-A by PHP Selector for domain - you have all selected modules, but if domain have PHP-B version and You try to activate PHP-A for subdomain, in such case phpinfo for PHP-A at subdomain will not show this modules? (My English not so good, so I need to ask).
 
For example:

1) In PHP SELECTOR you configure modules for every version PHP (B) and choose default one for account, let's say that 7.4 (A)

2) in .htaccess you set for some file/directory OTHER version, let's say 7.1 (B)

A - 7.4 = default for account, with your modules
B - 7.1 = without your config ;( which you set in phpselector for 7.1
 
Just finish testing. Default 5.6, so domain's htaccess clean (because it uses default php)
for subdomain htaccess has:
RemoveHandler .php
SetHandler application/x-lsphp71
--
then put to subdomain test.php file with phpinfo string, open it in browser.
Check for Opcache and Yaml (disabled before) and didn't find it.
Come to another tab and enable Opcache and Yaml for 7.1, still keeping 5.6 as default.
Refresh tab with phpinfo for subdomains - modules now enabled.
So all works.
 
This not working for me. Do you have Litespeed (I don't know it's related or no)

Could you paste here "Additional .ini files parsed" from phpinfo() for both? Are they different like in my case?

On my setup ANY other (not default) PHP loaded via SetHandler in .htaccess have "default.ini" instead of alt_php.ini ;(((
 
Thank you. So... it's possible :O

Anyone any thoughts WHY I have "default.ini" instead of "alt_php.ini"? What Am I missing?
 
Uhhh, finally resolved.

If someone will have this issue:

create a file /etc/cl.selector/symlinks.rules with the following content: php.d.location = selector
And run the command to apply changes:

/usr/bin/selectorctl --apply-symlinks-rules
 
Back
Top