Can a single X2 host use 2 different versions of PHP?

 
Post new topic   Reply to topic    Aprelium Forum Index -> PHP
View previous topic :: View next topic  
Author Message
JMMotyer
-


Joined: 06 Jul 2005
Posts: 39
Location: Burlington (Toronto), Ontario, Canada

PostPosted: Mon Apr 25, 2022 5:05 am    Post subject: Can a single X2 host use 2 different versions of PHP? Reply with quote

Hello, folks.

I have a stupid question, which I'm pretty-sure cannot be accomplished, but I will ask anyway.

I have 8 hosts set up in X2: 7 hosts are using PHP 8.1.0, and 1 host is using PHP 7.4.0 (due to the limitation of a handful of scripts on this host requiring a maximum of PHP 7.4.0). Everything works perfectly with my hosts set up that way.

I am wondering if a single host on Abyss is capable of running 2 different versions of PHP on the same host, depending on the path/alias.

Example (all the below are on the SAME host):

https://domain1.com............... php 8.1.0
https://domain1.com/alias1...... php 8.1.0
https://domain1.com/alias2...... php 8.1.0
https://domain1.com/alias3...... php 8.1.0
https://domain1.com/alias4...... php 8.1.0
https://domain1.com/alias5...... php 8.1.0
https://domain1.com/alias6...... php 7.4.0
https://domain1.com/alias7...... php 7.4.0
https://domain1.com/alias8...... php 7.4.0
https://domain1.com/alias9...... php 7.4.0

Most likely it is NOT possible, but Abyss has surprised me in the past with its capabilities quite a few times, hence me asking.

Thank you in advance & have yourselves a great week.

Regards,
John
Back to top View user's profile Send private message
Horizon
-


Joined: 18 Feb 2022
Posts: 18

PostPosted: Mon Apr 25, 2022 9:25 am    Post subject: Reply with quote

Revision #2 (improved):

There's a trick that cans do what you want if you use URLRewrite:

1) Declare the PHP 8 interpreter for the .php8 extension.
2) Declare the PHP 7.4 interpreter for the .php74 extension.

3) Set the Script Path for PHP 8 to /php8/*.php8.
4) Set the Script Path for PHP 7.4 to /php74/*.php74.

5) In your root server directory create two folders:
- /php8
- /php74

6) Put your PHP 8 app in a folder within /php8.
7) Put your PHP 7.4 app in a folder within /php74.

8) Do a batch recursive symlink for all PHP files in /php8:
- all .php files get a .php8 symbolic link.
- the .php8 file is the symbolic link.

9) Do a batch recursive symlink for all PHP files in /php74:
- all .php files get a .php74 symbolic link.
- the .php74 file is the symbolic link.

Symbolic links don't take much additional disk space, and will pose as the real linked files when read.
Symbolic links are also available on Windows.


10) Create URLRewrite rules for your aliases:

Put these rules at the top of your Rewrite rules list.

The php app aliases need to match your PHP application folder names in the hostname entry's /php8 & /php74 directories.

- 10.1) PHP 7.4 application aliases:

Context: Relative to base
Base: /
Regular Expression: ^/(app1|app2)(|/.*?)(?:|/)$

∆ Apply to subrequests too: [x]

Action: Internal redirection
Redirect To: /php74/$1$2

Append Query String: [x]
Next Action: Continue with next rule

- 10.2) PHP 8 application aliases:

Context: Relative to base
Base: /
Regular Expression: ^/(app3|app4)(|/.*?)(?:|/)$

∆ Apply to subrequests too: [x]

Action: Internal redirection
Redirect To: /php8/$1$2

Append Query String: [x]
Next Action: Continue with next rule

11) Create URLRewrite rules for internal redirects:

- 11.1) Redirect all .php requests for the PHP 8 apps:

Context: Relative to base
Base: /php8
Regular Expression: ^(.+?)(?:\.php)(|/.*)$

∆ Apply to subrequests too: [x]

Action: Internal redirection
Redirect To: $1.php8$2

Append Query String: [x]
Next Action: Stop matching

- 11.2) Redirect all .php requests for the PHP 7.4 apps:

Context: Relative to base
Base: /php74
Regular Expression: ^(.+?)(?:\.php)(|/.*)$

∆ Apply to subrequests too: [x]

Action: Internal redirection
Redirect To: $1.php74$2

Append Query String: [x]
Next Action: Stop matching

12) Now afterwards you need to add your PHP application rewrites as you would typically do with a single PHP version.

- 12.1) Example for your third application (app3, PHP 8).

- Redirecting all pretty URLs to its index.php routing script:

Context: Relative to base
Base: /php8/app3
Regular Expression: ^.*$

Rewrite conditions:
REQUEST_FILENAME - Is not a file
REQUEST_FILENAME - Is not a directory

∆ Apply to subrequests too: [ ]

Action: Internal redirection
Redirect To: index.php%{REQUEST_FILENAME}

Append Query String: [x]
Next Action: Stop matching

13) Now it should be good with this method, I hope.

You shouldn't need to edit any PHP files to change the PHP references to PHP8 / PHP74, and all further requests for .php will be directed dynamically against .php8 or .php74, as you wish.

This ensures that the scripts are always interpreted by the correct PHP version.

Just remember that I didn't try this method yet, it may need to be refined a little before being considered perfect.

Your flow should become (taking into consideration rules that get skipped over):

1. /php8app/page-title-pretty-url/
2. -> /php8/php8app/page-title-pretty-url
3. -> /php8/php8app/index.php/page-title-pretty-url
4. -> /php8/php8app/index.php8/page-title-pretty-url

All this done in the background with internal redirects.
Users will not see any of these hidden server-side tricks.

That's likely not as easy as you wanted, but this method should do the trick.
Back to top View user's profile Send private message
Horizon
-


Joined: 18 Feb 2022
Posts: 18

PostPosted: Mon Apr 25, 2022 10:39 am    Post subject: Reply with quote

Example of how you would typically do symlinks with recursion for every folder:
Code:

int enumerate_files = 1;
int enumerate_folders = 2;

void main(string[] args)
{
    _do_symlinks(args[0]);
    // the first command-line parameter.
}

void _do_symlinks(string starting_directory)
{
    string[] files_list = _enumerate_directory(starting_directory, enumerate_files);

    foreach (string file in files_list)
    {
        if ( !_file_is_symlink(file) && !_file_has_symlink(file) )
        {
            _file_make_symlink(file);
        }
    }

    string[] folders_list = _enumerate_directory(starting_directory, enumerate_folders);

    foreach (string folder in folders_list)
    {
        _do_symlinks(folder);
        // _do_symlinks calling itself (recursion).
    }
}
[... the rest of the script ...]

(No matter which scripting language is used, the logic stays the same.)
Back to top View user's profile Send private message
admin
Site Admin


Joined: 03 Mar 2002
Posts: 1235

PostPosted: Tue Apr 26, 2022 9:48 pm    Post subject: Re: Can a single X2 host use 2 different versions of PHP? Reply with quote

JMMotyer,

It is possible provided that you use different file extensions for each version of PHP (as suggested by Horizon.)

In the very near future, we are going to improve the interpreter resolution mechanism (by exposing more parameters.) As a side effect, your use case will be very easy to configure.
_________________
Follow @abyssws on Twitter
Subscribe to our newsletter
_________________
Forum Administrator
Aprelium - https://aprelium.com
Back to top View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Aprelium Forum Index -> PHP All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB phpBB Group