Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve program path detection by using system path and PHP_BINDIR #3184

Closed
browniebraun opened this issue Jan 14, 2020 · 9 comments
Closed
Assignees
Labels
bug Undesired behaviour installer Installation issue resolved A fixed issue

Comments

@browniebraun
Copy link
Member

Module detection fails on a blank system if PHP has been installed in non-default location and in combination with PHP-FPM. path_php_binary is empty per default.

@netniV netniV self-assigned this Jan 14, 2020
@netniV
Copy link
Member

netniV commented Jan 14, 2020

Can you be more specific about how it is failing with examples of configuration and more description of the problem

@browniebraun
Copy link
Member Author

Will add some screenshots once I'm back in the office tomorrow morning.

@netniV
Copy link
Member

netniV commented Jan 15, 2020

Thanks, I'll take a look tomorrow then.

@cigamit cigamit added the unverified Some days we don't have a clue label Jan 17, 2020
@netniV netniV added bug Undesired behaviour installer Installation issue and removed unverified Some days we don't have a clue labels Jan 17, 2020
@netniV netniV changed the title Cacti 1.2.8 - PHP module detection failing Improve program path detection by using system path and PHP_BINDIR Jan 17, 2020
@netniV
Copy link
Member

netniV commented Jan 17, 2020

So, I've improved the program path detection code so that it now has our predefined list of folders, but it will also include the system path and PHP_BINDIR as a priority.

php > include('/usr/share/cacti/site/install/functions.php');
php > print_r (find_search_paths());
Array
(
    [0] => /usr/local/sbin
    [1] => /usr/local/bin
    [2] => /usr/sbin
    [3] => /usr/bin
    [4] => /sbin
    [5] => /bin
    [6] => /usr/games
    [7] => /usr/local/games
    [14] => /usr/local/spine/bin
    [15] => /usr/spine/bin
)
php > putenv('PHP_BINDIR=/bin');
php > print_r (find_search_paths());
Array
(
    [0] => /bin
    [1] => /usr/local/sbin
    [2] => /usr/local/bin
    [3] => /usr/sbin
    [4] => /usr/bin
    [5] => /sbin
    [7] => /usr/games
    [8] => /usr/local/games
    [15] => /usr/local/spine/bin
    [16] => /usr/spine/bin
)
php > putenv('PATH=/my/path1:/usr/local/bin:/mypath2');
php > print_r (find_search_paths());
Array
(
    [0] => /bin
    [1] => /my/path1
    [2] => /usr/local/bin
    [3] => /mypath2
    [5] => /sbin
    [6] => /usr/bin
    [7] => /usr/sbin
    [9] => /usr/local/sbin
    [10] => /usr/local/spine/bin
    [11] => /usr/spine/bin
)

As you can see, by setting the PATH or PHP_BINDIR changes the order of searching but also includes directories that might have been otherwise missed.

@netniV
Copy link
Member

netniV commented Jan 17, 2020

@BSOD2600 may want to double check this on the windows side but I did specify that the path separator is a semi colon (;) rather than colon (:) which unix uses so in theory the code should work the same.

@netniV netniV added the resolved A fixed issue label Jan 17, 2020
@TheWitness
Copy link
Member

I've found some customers who have their own PHP versions installed on NFS and added to their PATHs that don't match the install requirements of Cacti, and that this messes up the CLI but not the GUI.

We should be compensating for that somehow. I would prefer we always pick local paths, though that would be hard to detect, though not impossible. Maybe forcing a path in config.php is an option too.

@netniV
Copy link
Member

netniV commented Jan 19, 2020

Setting PHP_BINDIR will override all else. We could add a similar config variable as another step, but then which takes priority?

@TheWitness
Copy link
Member

I would say if you set it in config.php, it is right at the top of the array.

@netniV
Copy link
Member

netniV commented Jan 20, 2020

php > putenv('PHP_BINDIR=1');
php > $config = array('php_path'=>'2');
php > print_r(find_search_paths());
Array
(   
    [0] => 2
    [1] => 1
    [2] => /usr/local/sbin
    [3] => /usr/local/bin
    [4] => /usr/sbin
    [5] => /usr/bin
    [6] => /sbin
    [7] => /bin
    [8] => /usr/games
    [9] => /usr/local/games
    [16] => /usr/local/spine/bin
    [17] => /usr/spine/bin
)

So, this should now be in effect.

@netniV netniV closed this as completed Jan 20, 2020
@github-actions github-actions bot locked and limited conversation to collaborators Jun 30, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Undesired behaviour installer Installation issue resolved A fixed issue
Projects
None yet
Development

No branches or pull requests

4 participants