Multiple APACHE versions with multiple PHP versions - PHP.INI PROBLEM when switching.
Posted by: mediadigital (---.play-internet.pl)
Date: March 10, 2014 12:56PM

Version of Wamp Server: 2.4

I find PHP.INI switching rather confusing when using multiple APACHE versions with multiple PHP versions.
It works ok when changing just PHP version, the php.ini in APACHE bin directory is replaced by proper phpForApache.ini.

The problem starts when switching APACHE version also.
Consider the following scenario:

1. Switch from APACHE version A to apache version B on PHP version A.
2. Switch to PHP version B.
3. Switch to apache version A (ON PHP VERSION B ).

On step three WAMP loads php.ini from Apache version A directory, which in fact is still PHP version A php.ini file.

Then it overwrites phpForApache.ini in PHP version B with this version from Apache version A directory.

As a result PHP version B php.ini file is overwritten with php.ini from PHP version A.

Is there any solution for this issue?



Edited 2 time(s). Last edit at 03/10/2014 12:58PM by mediadigital.

Options: ReplyQuote
Re: Multiple APACHE versions with multiple PHP versions - PHP.INI PROBLEM when switching.
Posted by: RiggsFolly (---.as13285.net)
Date: March 10, 2014 03:01PM

Yes,

Here it is, I am afraid its a do it yourself fix rather than an installable fix.

I also suggest you look at this post and apply some other fixes for WampServer 2.4 [forum.wampserver.com]



A "bug" in WampServer 2.4 has been detected.
This bug only occurs when switching versions of Apache and generates an incorrect phpForApache.ini file in the PHP version that was running with the Apache that is being switched away from.

This explanations will assumes we are running Apache 2.4.7 and PHP 5.5.6 for demonstration purposes and to show what WAMP does in the following situations.
These versions may or may not actually exist.

All the code that does any of this switching is actually run as PHPCLI scritps that live in the \wamp\scripts folder.
This is why there is a file in the \wamp\bin\php folder called DO_NOT_DELETE_5.4.16.txt, becasue all these CLI scripts depend upon the PHP version mentioned there existing.

- 1 - Change the PHP version
- So this is the senario, we are running Apache 2.4.7 with PHP 5.5.6 and we want to switch just the version of PHP to PHP 5.5.4

These are the relevant enties in wampserver.ini
Type: item; Caption: "5.5.4"; Action: multi; Actions:switchPhp5.5.4

The switching process is performed by calling (Among others):

Action: run; FileName: "C:/wamp/bin/php/php5.5.4/php-win.exe";Parameters: "switchPhpVersion.php 5.5.4";WorkingDir: "C:/wamp/scripts"; Flags: waituntilterminated
Action: run; FileName: "C:/wamp/bin/php/php5.5.4/php-win.exe";Parameters: "-c . refresh.php";WorkingDir: "C:/wamp/scripts"; Flags: waituntilterminated


First the script C:/wamp/scripts/switchPhpVersion.php is run from the command line, where the paramter is the version of PHP we want to switch to i.e 5.5.4
That script finally calls C:/wamp/scripts/refresh.php which regenerates the file wampmanager.ini, this is so the Wampmanager menu are based on the new modified settings.

This result of this is:
- Click on the WampManager menu to switch to PHP5.5.4
- Call switchPhpVersion function with parameter ( 5.5.4 )
- The function switchPhpVersion, moves the current php.ini from the Apache folder to the PHP folder ( php folder for the version running )
copy ( C:/wamp/bin/apache/apache2.4.7/bin/php.ini,C:/wamp/bin/php/php5.5.6/phpForApache.ini ) ;

- Now it gets the php.ini from the new php version file
copy ( C:/wamp/bin/php/php5.5.4/phpForApache.ini,C:/wamp/bin/apache/apache2.4.7/bin/php.ini ) ;

- WampIniset Function - recreates the file ../wampmanager.conf with the new current version information
- Script refresh.php - regenerates the ../wampmanager.ini

So the PHP ini file for PHP5.5.6 is copied from the Apache folder back to its correctly versioned PHP folder before the New PHP version php5.5.4 has its phpForApache.ini file copied to the Apache folder.


- 2 - Change of Apache
So this is the senario, we are running Apache 2.4.7 with PHP 5.5.6 and we want to switch to Apache version 2.4.4. The PHP version should remain the same.

- Click on the WampManager menu to switch to Apache 2.4.4

Type: item; Caption: "2.4.4"; Action: multi; Actions:switchApache2.4.4

calling (Among others):

[switchApache2.4.4]
Action: service; Service: wampapache; ServiceAction: stop; Flags: ignoreerrors waituntilterminated
Action: run; FileName: "C:/wamp/bin/apache/apache2.4.7/bin/httpd.exe"; Parameters: "-n wampapache -k uninstall"; ShowCmd: hidden; Flags: ignoreerrors waituntilterminated
Action: closeservices; Flags: ignoreerrors
Action: run; FileName: "C:/wamp/bin/php/php5.5.4/php-win.exe";Parameters: "switchApacheVersion.php 2.4.4";WorkingDir: "C:/wamp/scripts"; Flags: waituntilterminated
Action: run; FileName: "C:/wamp/bin/php/php5.5.4/php-win.exe";Parameters: "switchPhpVersion.php 5.5.6";WorkingDir: "C:/wamp/scripts"; Flags: waituntilterminated
Action: run; FileName: "C:/wamp/bin/apache/apache2.4.4/bin/httpd.exe"; Parameters: "-n wampapache -k install"; ShowCmd: hidden; Flags: waituntilterminated
Action: run; FileName: "net"; Parameters: "start wampapache"; ShowCmd: hidden; Flags: waituntilterminated
Action: run; FileName: "C:/wamp/bin/php/php5.5.4/php-win.exe";Parameters: "-c . refresh.php";WorkingDir: "C:/wamp/scripts"; Flags: waituntilterminated


- Stop and uninstall the current wampapache Service : launch httpd.exe with parameter -k uninstall wampapache
- Change Apache ( from 2.4.7 to 2.4.4 ) by the command line script C:/wamp/scripts/switchApacheVersion.php with as parameter the new Apache 2.4.4
- Call PHP control script C:/wamp/scripts/switchPhpVersion.php with a parameter of the active PHP version i.e. PHP 5.5.6 to update php.ini in the newly activated Apache.
- Install wampapache as a Service : launch httpd.exe with parameter -n - k install wampapache
- Start the wampapache Service
- Finally the script C:/wamp/scripts/refresh.php is called which regenerates the file wampmanager.ini, so the Wampmanager menu is based on the new modified settings.

This results in the trace :

- In the script switchApacheVersion.php - Call function wampIniSet ; (/wampmanager.conf, 2.4.4 . ).
- WampIniset Function - Writing file ../wampmanager.conf
- Call switchPhpVersion function ( 5.5.6 )
- In function switchPhpVersion - Saves the current php.ini
copy ( C:/wamp/bin/apache/apache2.4.4/bin/php.ini, C:/wamp/bin/php/php5.5.6/phpForApache.ini ) ;

- Place the new php.ini
copy ( C:/wamp/bin/php/php5.5.6/phpForApache.ini, C:/wamp/bin/apache/apache2.4.4/bin/php.ini ) ;
- WampIniset Function - Writing file ../wampmanager.conf
- Script refresh.php - was regenerated ../wampmanager.ini


And this is where the bug is!
It overwrites the phpForApache.ini file in the currently running PHP version (5.5.6) with the php.ini file from the newly activated Apache2.4.4, but of course we have no idea what version of PHP this php.ini file came from, as we dont know what version of PHP we last used in this version of Apache.

It should have taken the php.ini from the old Apache (2.4.7) and not that of the new (2.4.4).

- 3 - Solution

It is quite complicated in the script to know what the old version of Apache was, once it has changed Apache.

At the end of all operations to change the configuration of WampServer, whatever these operations :
Version of Apache, PHP version, MySQL version, Apache modules, PHP extensions, PHP settings, management services, etc...
the script C:/wamp/scripts/refresh.php is executed, so that the file wamp/wampmanager.ini always reflects the current configuration of WampServer.

So we will inform the script wamp/scripts/swithPhpVersion.php what Apache version is currently in force, but only if we are changing Apache versions.

To do this, we will slightly modify the script wamp/scripts/refresh.php to add a second parameter
- the current Apache
- calls the script C:/wamp/scripts/switchPhpVersion.php but only the menu items change Apache ( It is unnecessary to add in the calls for change of PHP version.)

So in the file wamp/scripts/refresh.php

replace :
Action: run; FileName: "'.$c_phpCli.'";Parameters: "switchPhpVersion.php '.$wampConf['phpVersion'].'";WorkingDir: "'.$c_installDir.'/scripts"; Flags: waituntilterminated
with
Action: run; FileName: "'.$c_phpCli.'";Parameters: "switchPhpVersion.php '.$wampConf['phpVersion'].' '.$wampConf['apacheVersion'].'";WorkingDir: "'.$c_installDir.'/scripts"; Flags: waituntilterminated

This change will use the PHP version from the wamp/wampmanager.ini file, but only the items change Apache, for example:

Action: run; FileName: "C:/wamp/bin/php/php5.5.4/php-win.exe";Parameters: "switchPhpVersion.php 5.5.6";WorkingDir: "C:/wamp/scripts"; Flags: waituntilterminated
is replaced by
Action: run; FileName: "C:/wamp/bin/php/php5.5.4/php-win.exe";Parameters: "switchPhpVersion.php 5.5.6 2.4.7";WorkingDir: "C:/wamp/scripts"; Flags: waituntilterminated
which was added in the second parameter, the current version of Apache.
Now, we must detect the second parameter in the script change PHP versions.

In the file wamp/scripts/switchPhpVersion.php

replace
switchPhpVersion($newPhpVersion) ;
With
//[modif oto] Test if second parameter exists. Apache common
switchPhpVersion($newPhpVersion,(($_SERVER['argc'] >= 3) ? $_SERVER['argv'][2] : '')) ;

It should also take into account this parameter in the switchPhpVersion function:

So in the file wamp/scripts/wampserver.lib.php

replace

function switchPhpVersion($newPhpVersion)
{
    require 'config.inc.php' ;
with

//[modif oto] Ajout version Apache courante si basculement version Apache.
function switchPhpVersion($newPhpVersion,$oldApacheVersion="" )
{
    require 'config.inc.php';
    //[modif oto] - Chemin php.ini courant si changement version Apache.
    if(empty($oldApacheVersion))
      $c_phpOldConfFile = $c_phpConfFile;
    else
      $c_phpOldConfFile = $c_apacheVersionDir.'/apache'.$oldApacheVersion.'/'.$wampConf['apacheExeDir'].'/'.$wampConf['phpConfFile'] ;

and replace

         // on sauvegarde le php.ini courant
            copy($c_phpConfFile,$c_phpVersionDir.'/php'.$wampConf['phpVersion'].'/'.$phpConfFileForApache) ;
with
        // on sauvegarde le php.ini courant
            copy($c_phpOldConfFile,$c_phpVersionDir.'/php'.$wampConf['phpVersion'].'/'.$phpConfFileForApache) ;
{/code]

Now, assuming we have Apache 2.4.7 and PHP 5.5.6 configured as current, change the Apache version to 2.4.4, we obtain the trace:
 - SwitchPhpVersion call function (5.5.6)
 - In function switchPhpVersion - Saves the current php.ini
   copy (C:/wamp/bin/apache/apache2.4.7/bin/php.ini,C:/wamp/bin/php/php5.5.6/phpForApache.ini);

 - Place the new php.ini
   copy (D:/wamp/bin/php/php5.5.6/phpForApache.ini,C:/wamp/bin/apache/apache2.4.4/bin/php.ini);

 - WampIniset Function - Writing file ../wampmanager.conf
 - Script refresh.php - was regenerated ../wampmanager.ini

It has saved the current php.ini from the old Apache version 2.4.7, and loaded php.ini into the new version of Apache 2.4.4.
This description was a bit long, but it helps to understand the internal operation of WampServer.

---------------------------------------------------------------------------------------------
(Windows 10 Pro 64bit) (Wampserver 3.3.4 64bit) Aestan Tray Menu 3.2.5.4
<Apache versions MULTIPE> <PHP versions MULTIPLE> <MySQL Versions MULTIPLE>
<MariaDB versions MULTIPLE> <phpMyAdmin versions MULTIPLE> <MySQL Workbench 8.0.23>
Read The Manuals Apache -- MySQL -- PHP -- phpMyAdmin 
Get your Apache/MySQL/mariaDB/PHP ADDONs here from the WAMPServer alternate Repo
-X-X-X- Backup your databases regularly Here is How dont regret it later! Yes even when developing -X-X-X-

Options: ReplyQuote


Sorry, only registered users may post in this forum.