richardforth / apache2buddy

apache2buddy
Apache License 2.0
386 stars 72 forks source link

sub get_php_setting breaks on systems with multiple versions of php installed #415

Closed kevin-j-morse closed 7 months ago

kevin-j-morse commented 7 months ago

On a Ubuntu LTS system that has been upgraded from e.g. 20.04 to 22.04 there will often exist multiple versions of PHP

20.04 uses PHP 7.4, 22.04 uses PHP 8.1, and 24.04 will probably use 8.3

get_php_setting breaks in this case because after locating /etc/php/7.4/cli/php.ini the script sees the /cli/ and then starts looking for another php.ini. It is the search for another php.ini that is not quite working correctly.

After checking for /etc/php5/apache2/php.ini the script correctly calls my @files = glob "/etc/php/*/apache2/php.ini"; but in cases where there are more than one items in the list it incorrectly goes looking for glob "/etc/php/*/fpm/php.ini" instead of using the last entry in the list by setting our $real_config = @files[-1];

This results in the message

VERBOSE: PHP: Loaded Configuration File => /etc/php/7.4/cli/php.ini VERBOSE: PHP: Attempting to find real apache php.ini file... VERBOSE: PHP: Real apache php.ini file is Not Found., using that... Use of uninitialized value $apache_proc_php in concatenation (.) or string at - line 2524 (#1)

The way I solved this is to remove all the code from lines 1350 to 1360 and replace with our $real_config = @files[-1];

I think this would break in cases where someone has fpm installed because you would never search for the glob "/etc/php/*/fpm/php.ini";

Maybe instead the if condition to search for fpm php.ini could be reached if the length of the list was 0 and if it wasn't then grab the last element of the list?

I realize this code is not being maintained but posting here in case this helps someone.

richardforth commented 7 months ago

Thanks for reporting this issue, but as you rightly said, im no longer maintaining this code. Apache2buddy is getting less and less relevant these days with moves to worker mode and PHP-FPM. Apache2buddy was only ever written to support mod-php /apache and hardly anyone uses it these days, so Ive stopped maintaining it. However I am glad you fixed it and you are welcome to fork it and maintain a version that works for you. I dont intend to support multiple PHP versions on one box, apache2buddy wasn't meant to be PHP-centric, so its becoming less and less relevant with these more complex setups.