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

evathias

Verified User
Joined
Mar 18, 2019
Messages
16
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
 

smtalk

Administrator
Staff member
Joined
Aug 22, 2006
Messages
8,911
Location
LT, EU
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.
 

explosive

Verified User
Joined
Dec 29, 2010
Messages
180
Location
PL/EU
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?
 

smtalk

Administrator
Staff member
Joined
Aug 22, 2006
Messages
8,911
Location
LT, EU
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).
 

chonk

Verified User
Joined
Jan 3, 2017
Messages
26
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>
 

explosive

Verified User
Joined
Dec 29, 2010
Messages
180
Location
PL/EU
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.
 

smtalk

Administrator
Staff member
Joined
Aug 22, 2006
Messages
8,911
Location
LT, EU
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.
 

explosive

Verified User
Joined
Dec 29, 2010
Messages
180
Location
PL/EU
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)
 

explosive

Verified User
Joined
Dec 29, 2010
Messages
180
Location
PL/EU
@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

Verified User
Joined
Feb 23, 2018
Messages
169
Location
UA
@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).
 

explosive

Verified User
Joined
Dec 29, 2010
Messages
180
Location
PL/EU
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
 

Zhenyapan

Verified User
Joined
Feb 23, 2018
Messages
169
Location
UA
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.
 

explosive

Verified User
Joined
Dec 29, 2010
Messages
180
Location
PL/EU
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 ;(((
 

explosive

Verified User
Joined
Dec 29, 2010
Messages
180
Location
PL/EU
Thank you. So... it's possible :O

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

explosive

Verified User
Joined
Dec 29, 2010
Messages
180
Location
PL/EU
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
 
Top