Two php version side by side

Problems with the Windows version of XAMPP, questions, comments, and anything related.

Two php version side by side

Postby alescan » 15. April 2020 17:15

Hi everyone, i'm using xampp for many years and had not a problem.
But now I have thi issue, I need to have two php version on one instances of xammp so i downloaded the version i needed and make a new directory into xampp root and edited php.ini extension dir.
In the httpd-xampp.conf i inserted this:
Code: Select all
ScriptAlias /php73 "C:/xampp/php73"
Action application/x-httpd-php73-cgi /php73/php-cgi.exe
<Directory "C:/xampp/php56">
    AllowOverride None
    Options None
    Require all denied
    <Files "php-cgi.exe">
        Require all granted
    </Files>
</Directory>

I only need one directory to use the second version so I inserted below:
Code: Select all
<Directory "C:\xampp\htdocs\my_old_project1">
    <FilesMatch "\.php$">
        SetHandler application/x-httpd-php73-cgi
    </FilesMatch>
</Directory>

The server start without error but when i request the page that need the old version it gives me a 500 error, in the windows event log i found this for every extension:
Code: Select all
PHP Warning: PHP Startup: Unable to load dynamic library 'mysqli' (tried: E:\xampp\php\ext\mysqli (The specified module could not be found.), E:\xampp\php\ext\php_mysqli.dll (The specified procedure could not be found.)) (E:\xampp\php73\php-cgi.exe)

The problem is that it search for the extension enabled in the "default" version of php (not the second) and in its folder.
alescan
 
Posts: 8
Joined: 15. April 2020 16:58
XAMPP version: 7.4.1
Operating System: Server 2016

Re: Two php version side by side

Postby Nobbie » 15. April 2020 20:10

Therefore you should create two VirtualHosts for your PHP files, one with PHP5 and one with PHP7.

But there is stilll one problem, which might be unsolveable: if Windows loads a DLL by name and another applications requires the same DLL (by name) but from a different location, there is no way to tell Windows to do so. You cannot load a DLL from another location which already has been loaded from a different location. That can get a major problem when you want to run two different PHP versions in the same session.
Nobbie
 
Posts: 11916
Joined: 09. March 2008 13:04

Re: Two php version side by side

Postby alescan » 15. April 2020 20:24

Nobbie wrote:Therefore you should create two VirtualHosts for your PHP files, one with PHP5 and one with PHP7.

But there is stilll one problem, which might be unsolveable: if Windows loads a DLL by name and another applications requires the same DLL (by name) but from a different location, there is no way to tell Windows to do so. You cannot load a DLL from another location which already has been loaded from a different location. That can get a major problem when you want to run two different PHP versions in the same session.


I know that, but the server is also available on internet, and response only on one domain, so i need it to make a choice based on directory like i tried.
The extension are also available from th second ext directory, how can I make the second version load them from its own directory?
XAMPP 7.4.1
alescan
 
Posts: 8
Joined: 15. April 2020 16:58
XAMPP version: 7.4.1
Operating System: Server 2016

Re: Two php version side by side

Postby Nobbie » 15. April 2020 21:00

alescan wrote:how can I make the second version load them from its own directory?


I have no idea.

There are lots of options to serve from different servers (i.e. using Reverse Proxy), but i dont know any option how to load different DLLs with the same name from different folders, Maybe you can specify the full pathnames of the DLLs in php.ini? I dont know, only an idea.

I would go for different servers, but as you dont want, i cannot help any further.
Nobbie
 
Posts: 11916
Joined: 09. March 2008 13:04

Re: Two php version side by side

Postby alescan » 16. April 2020 09:16

In xampp.conf I found this setting:
Code: Select all
<IfModule php7_module>
    PHPINIDir "E:/xampp/php"
</IfModule>
and I think thats the problem.
I tried to insert a new one but when try to start the server I get the following error:
Code: Select all
The Apache service named  reported the following error:
>>> Only first PHPINIDir directive honored per configuration tree - subsequent ones ignored.


So the question is if anyone know how tell apache to use the other php.ini file for the other version.
XAMPP 7.4.1
alescan
 
Posts: 8
Joined: 15. April 2020 16:58
XAMPP version: 7.4.1
Operating System: Server 2016

Re: Two php version side by side

Postby gsmith » 17. April 2020 09:47

As far as I know (and read earlier searching google as well) you cannot have multiple php versions with one running in the Apache process ( LoadModule php7_module /xampp/php/php7apache2_4.dll ). That leaves you with two options;

CGI

Pros:
Runs outside the Apache process. Because of this cannot crash Apache like can happen with the module.
Have multiple php versions.
Can use the Non-Thread Safe versions of PHP.

Cons:
Has to spawn a new process on every request which makes every request a little slower.


FASTCGI

Pros:
Runs outside the Apache process. Because of this cannot crash Apache like can happen with the module.
Have multiple php versions.
Can use the Non-Thread Safe versions of PHP.
Keeps the process running for other requests until it hits one of a number of possible configurable options (FcgidMaxRequestsPerProcess, FcgidIdleTimeout, FcgidProcessLifeTime, etc.)

Cons:
I'm sure there are some, I just do not know of any.

============================================================================================

FastCGI is best in my opinion.
You will have to comment out all the php configuration items in httpd-xampp.conf if you go with this option.
Make sure there is no php in your system path and the various versions will use the php ini files in their specific php folders.

It's not too difficult to configure

You can get mod_fcgid from Apache Haus or Apache Lounge.
gsmith
 
Posts: 268
Joined: 29. November 2013 18:04
Location: San Diego
XAMPP version: 0.0.0
Operating System: Win 10/2012R VS 14,15,16

Re: Two php version side by side

Postby alescan » 17. April 2020 17:25

Thank you very much, it really helped me.
But now its' happenging a strange thing, i've putted a test page to see the php version and it's correct but if I request the homepage it's blank also in the html view
In the test page I noticed that it's still using the "default" php.ini
here the xampp.conf:
Code: Select all
#
# PHP-Module setup
#
#LoadFile "E:/xampp/php/php7ts.dll"
#LoadFile "E:/xampp/php/libpq.dll"
#LoadModule php7_module "E:/xampp/php/php7apache2_4.dll"

#<FilesMatch "\.php$">
#    SetHandler application/x-httpd-php
#</FilesMatch>
#<FilesMatch "\.php.old$">
#    SetHandler application/x-httpd-php
#</FilesMatch>
#<FilesMatch "\.phps$">
#    SetHandler application/x-httpd-php-source
#</FilesMatch>

LoadModule fcgid_module modules/mod_fcgid.so

<IfModule fcgid_module>
   FcgidInitialEnv PATH "E:/xampp/php"
   FcgidInitialEnv SystemRoot "C:/Windows"
   FcgidInitialEnv SystemDrive "C:"
   FcgidInitialEnv TEMP "E:/xampp/tmp"
   FcgidInitialEnv TMP "E:/xampp/tmp"
   FcgidInitialEnv windir "C:/windows"
   FcgidIOTimeout 64
   FcgidConnectTimeout 16
   FcgidMaxRequestsPerProcess 1000
   FcgidMaxProcesses 3
   FcgidMaxRequestLen 8131072
   # Location php.ini:
   FcgidInitialEnv PHPRC "E:/xampp/php"
   FcgidInitialEnv PHP_FCGI_MAX_REQUESTS 1000

   <Files ~ "\.php$">
      Options Indexes FollowSymLinks ExecCGI
      AddHandler fcgid-script .php
      FcgidWrapper "E:/xampp/php/php-cgi.exe" .php
   </Files>
</IfModule>

<IfModule fcgid_module>
  <Location />
    FcgidWrapper "E:/xampp/php/php-cgi.exe" .php
  </Location>
  <Location /openstamanager>
    FcgidWrapper "E:/xampp/php73/php-cgi.exe" .php
 </Location>   
</IfModule>

#
# PHP-CGI setup
#
#<FilesMatch "\.php$">
#    SetHandler application/x-httpd-php-cgi
#</FilesMatch>
#<IfModule actions_module>
#    Action application/x-httpd-php-cgi "/php-cgi/php-cgi.exe"
#</IfModule>


#<IfModule php7_module>
#    PHPINIDir "E:/xampp/php"
#</IfModule>

<IfModule mime_module>
    AddType text/html .php .phps
</IfModule>

Any idea about why?
XAMPP 7.4.1
alescan
 
Posts: 8
Joined: 15. April 2020 16:58
XAMPP version: 7.4.1
Operating System: Server 2016

Re: Two php version side by side

Postby gsmith » 18. April 2020 18:36

Yeah, this is why I mentioned to NOT have php in the system's PATH environment variable. I'm telling you now that you do but it's not necessarily your fault. I just opened the Xampp control panel, clicked on the Shell button and typed "path," look what I found

Code: Select all
ROCKY@FROSTBITEFALLS d:\xampp
# path
PATH=D:\xampp\;D:\xampp\php;D:\xampp\perl\site\bin;D:\xampp\perl\bin;D:\xampp\apache\bin;D:\xampp\mysql\bin;D:\xampp\FileZillaFTP;D:\xampp\MercuryMail;D:\xampp\sendmail;D:\xampp\webalizer;D:\xampp\tomcat\bin;

If the xampp shell adds all that I could easily imagine that it also does this when starting Apache.

Disclosure: I use my own build of Apache and not Xampp. I just keep a copy of xampp around so as to know what users on this forum have themselves.

Open a regular Windows Command Prompt and type "path" without the quotes and see what all it tells you. If you do not see an entry for any php location then use, again without quotes, "cd /d E:\xampp\apache\bin" and then "httpd" and check out if you then get the correct php.ini loaded.
gsmith
 
Posts: 268
Joined: 29. November 2013 18:04
Location: San Diego
XAMPP version: 0.0.0
Operating System: Win 10/2012R VS 14,15,16

Re: Two php version side by side

Postby Altrea » 18. April 2020 19:33

The XAMPP shell adds temporarily directory to the PATH variable which are only valid for this single command line window. That is just for convenient purposes and does not have anything to do with the starting methods xampp uses.
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 10727
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 10 Pro x64

Re: Two php version side by side

Postby alescan » 18. April 2020 19:54

But why if request domain/folder/test.php i get the correct php info page but when i request domain/foder i get it blank. If it's a path problem i shouldn't get the info page either.
XAMPP 7.4.1
alescan
 
Posts: 8
Joined: 15. April 2020 16:58
XAMPP version: 7.4.1
Operating System: Server 2016

Re: Two php version side by side

Postby gsmith » 18. April 2020 21:54

http://domain/folder will give whatever is set for DirectoryIndex in Apache which on xampp is anyone of
index.php index.pl index.cgi index.asp index.shtml index.html index.htm default.php default.pl default.cgi default.asp default.shtml default.html default.html home.php home.pl home.cgi home.asp home.shtml home.html home.htm.

If there's no index.php it will next look for index.pl and so on in order to serve up. So what is it finding in that list in said folder, that's what it's serving up.
gsmith
 
Posts: 268
Joined: 29. November 2013 18:04
Location: San Diego
XAMPP version: 0.0.0
Operating System: Win 10/2012R VS 14,15,16

Re: Two php version side by side

Postby alescan » 19. April 2020 14:05

Of course there is, it's not giving me a 404 error. it's just a blank page, even if I look the html source page.
XAMPP 7.4.1
alescan
 
Posts: 8
Joined: 15. April 2020 16:58
XAMPP version: 7.4.1
Operating System: Server 2016

Re: Two php version side by side

Postby alescan » 19. April 2020 18:36

I tried to comment out in the conf file this
Code: Select all
  #<Location /openstamanager>
    #FcgidWrapper "E:/xampp/php73/php-cgi.exe" .php
 #</Location>
and get the homepage normally.
XAMPP 7.4.1
alescan
 
Posts: 8
Joined: 15. April 2020 16:58
XAMPP version: 7.4.1
Operating System: Server 2016

Re: Two php version side by side

Postby gsmith » 21. April 2020 23:56

Sorry for me delay in responding.

if this is in the global config (not in any vhost)
Code: Select all

</IfModule>
   <Files ~ "\.php$">
      Options Indexes FollowSymLinks ExecCGI
      AddHandler fcgid-script .php
      FcgidWrapper "E:/xampp/php/php-cgi.exe" .php
   </Files>
</IfModule>


Then you should not need the one for Location /
gsmith
 
Posts: 268
Joined: 29. November 2013 18:04
Location: San Diego
XAMPP version: 0.0.0
Operating System: Win 10/2012R VS 14,15,16

Re: Two php version side by side

Postby JJ_Tagy » 22. April 2020 00:54

gsmith wrote:</IfModule>

@gsmith: FYI on your open
JJ_Tagy
 
Posts: 786
Joined: 30. January 2012 13:44
XAMPP version: 5.5.15
Operating System: Windows 10 Pro x64


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 96 guests