[BUG FIX] Switching versions of Apache saves the wrong php.ini in the phpForApache.ini
Posted by: RiggsFolly (---.as13285.net)
Date: December 17, 2013 04:14PM

A "bug" in WampServer 2.4 was detected by Artemus24.
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) ;

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.


Originally posted by otomatic in French so all kudos belong to him, only the English translation was done by me, and before you ask, no I dont speak French but I can use Google Translator and then try and sort out the position of the verb.

---------------------------------------------------------------------------------------------
(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-



Edited 1 time(s). Last edit at 12/17/2013 09:51PM by RiggsFolly.

Options: ReplyQuote
Re: [BUG FIX] Switching versions of Apache saves the wrong php.ini in the phpForApache.ini
Posted by: stevenmartin99 (Moderator)
Date: December 17, 2013 08:11PM

Last component version is stored in the wampmanager.conf

Steven Martin
stevenmartin99@gmail.com
stevenmartin99@hotmail.com
PampServer.com - [pampserver.com]

Options: ReplyQuote
Re: [BUG FIX] Switching versions of Apache saves the wrong php.ini in the phpForApache.ini
Posted by: RiggsFolly (---.as13285.net)
Date: December 17, 2013 09:52PM

Yea, I was thinking that as well, but I am just the messenger, talk to otomatic.

---------------------------------------------------------------------------------------------
(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
Re: [BUG FIX] Switching versions of Apache saves the wrong php.ini in the phpForApache.ini
Posted by: stevenmartin99 (Moderator)
Date: December 18, 2013 12:09AM

I Know, this wamp is getting worse!!!

hopefully ill be finished PampServer soon and people will have an alternative!






Steven Martin
stevenmartin99@gmail.com
stevenmartin99@hotmail.com
PampServer.com - [pampserver.com]



Edited 3 time(s). Last edit at 12/18/2013 12:34AM by stevenmartin99.

Options: ReplyQuote
Re: [BUG FIX] Switching versions of Apache saves the wrong php.ini in the phpForApache.ini
Posted by: Otomatic (Moderator)
Date: December 18, 2013 07:33PM

stevenmartin99 Wrote:
-------------------------------------------------------
> Last component version is stored in the wampmanager.conf

Hi,

The version currently in use is shown in wampmanager.conf, but previously used version does not change.

In wampmanager.conf
- Time 0
[php]
phpVersion = "5.3.28"
phpLastKnown = 5.5.4

[apache]
apacheVersion = "2.4.7"
apacheLastKnown = 2.4.6

- Time 1 - Switch to PHP 5.5.7
[php]
phpVersion = "5.5.7"
phpLastKnown = 5.5.4

[apache]
apacheVersion = "2.4.7"
apacheLastKnown = 2.4.6
phpLastKnown does not show the previous version used (5.3.28)

- Time 2 - Switch to Apache 2.4.4
[php]
phpVersion = "5.5.7"
phpLastKnown = 5.5.4

[apache]
apacheVersion = "2.4.4"
apacheLastKnown = 2.4.6
apacheLastKnown does not show the previous version used (2.4.7)

I thought I could use the information wampmanager.conf to the previous version, but this was not possible. Nevertheless, I will look at why moduleLastKnown is not changed.

---------------------------------------------------------------
Documentation Apache - Documentation PHP - Documentation MySQL - Wampserver install files & addons

Options: ReplyQuote
Re: [BUG FIX] Switching versions of Apache saves the wrong php.ini in the phpForApache.ini
Posted by: Otomatic (Moderator)
Date: December 19, 2013 05:03PM

Hi,

In a remark of Artemus24 and several assumptions :
- PHP 5.2.x is incompatible with Apache 2.4
- PHP 5.2.x is totally obsolete
- Apache and PHP compiled VC11 are not supported under Windows XP
- Symbolic links work from Windows Vista. (Vista, W7, W8, W8.1) (Nota 1)
- Symbolic links work from PHP 5.3.0 (5.3.x, 5.4.x, 5.5.x)

We will limit the new way to fix the bug in WampServer to:
- PHP 5.3.0+ and Windows Vista+ and Apache 2.4.0+
and this will be corrected by the creation/modification of symbolic links seamlessly with all other shares in the php.ini file.

In the file wamp\scripts\wampserver.lib.php
remplace:
    // on sauvegarde le php.ini courant
    copy($c_phpConfFile,$c_phpVersionDir.'/php'.$wampConf['phpVersion'].'/'.$phpConfFileForApache) ;
    
    //on place le nouveau php.ini
    copy($c_phpVersionDir.'/php'.$newPhpVersion.'/'.$phpConfFileForApache,$c_phpConfFile) ;
by
    //on place le nouveau php.ini
    //[modif oto] - Create symbolic link to php.ini file of active PHP version
    $target = $c_phpVersionDir."/php".$newPhpVersion."/".$phpConfFileForApache;
    $link = $c_apacheVersionDir."/apache".$wampConf['apacheVersion']."/".$wampConf['apacheExeDir']."/php.ini";
    if(is_file($link) || is_link($link))
    	unlink($link);
    symlink($target, $link);
In this way we keep unchanged the file wamp/bin/php/php5.xy/php.ini that is used by php command line (CLI).
All changes in "php.ini" seen by Apache or edited by Wampmanager menu will actually be made ​​in the file wamp/bin/php/php5.xy/phpFor apache.ini seamlessly for the user.

Nota 1 : ) It is possible to support Symbolic Links under Windows XP SP3 : Symbolic Links for Windows XP

---------------------------------------------------------------
Documentation Apache - Documentation PHP - Documentation MySQL - Wampserver install files & addons



Edited 1 time(s). Last edit at 12/20/2013 09:46AM by Otomatic.

Options: ReplyQuote
Re: [BUG FIX] Switching versions of Apache saves the wrong php.ini in the phpForApache.ini
Posted by: Otomatic (Moderator)
Date: December 19, 2013 07:24PM

Quote
Otomatic
Nevertheless, I will look at why moduleLastKnown is not changed.

For Last used Apache version, in wamp\scripts\switchApacheVersion.php file, just before:
wampIniSet($configurationFile, $apacheConf);
insert
$apacheConf['apacheLastKnown'] = $wampConf['apacheVersion'];

For last used PHP version, in wamp\scripts\wampserver.lib.php file, just before:
    $wampIniNewContents['phpVersion'] = $newPhpVersion;
insert
    $wampIniNewContents['phpLastKnown'] = $wampConf['phpVersion'];

For last used MySQL version, in wamp\scripts\switchMysqlVersion.php file, just before:
$mysqlConf['mysqlVersion'] = $newMysqlVersion;
insert
$mysqlConf['mysqlLastKnown'] = $wampConf['mysqlVersion'];

---------------------------------------------------------------
Documentation Apache - Documentation PHP - Documentation MySQL - Wampserver install files & addons

Options: ReplyQuote


Sorry, only registered users may post in this forum.