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

Unable to update PHP location during installation due to incorrect CLI environment #2311

Closed
JDavidRogers opened this issue Jan 15, 2019 · 9 comments
Labels
bug Undesired behaviour resolved A fixed issue

Comments

@JDavidRogers
Copy link

Forum link: https://forums.cacti.net/viewtopic.php?f=21&t=59445&sid=b9fe62f5b46182adb2c65c7915bf9e5e

Apache version: Apache/2.4.37
PHP version: 5.6.39
MySQL version: 10.1.37-MariaDB
Distro Name: CentOS Linux release 7.6.1810 (Core)
Kernel Version: 3.10.0-957.1.3.el7.x86_64

The install/upgrade wizard fails on step 5 when checking the path of PHP. The issue can be worked around by manually removing the $_SERVER['REQUEST_METHOD'] and $_SERVER['REMOTE_ADDR'] checks within cli_test.php

Also, not sure if related, but when manually correcting the above issue, the final part of the installation loops repeatedly and does not complete. The following errors repeat every few seconds in the cacti.log when debug level is set to 5:

2019/01/13 09:56:18 - INSTALL-STEP: notice: Install Parameters: array ( 'Runtime' => 'Web', 'Step' => '97', 'Eula' => '1', )
2019/01/13 09:56:18 - INSTALL-STEP: notice: Initial: '97'
2019/01/13 09:56:18 - INSTALL-STEP: notice: Previously complete: NULL
2019/01/13 09:56:18 - INSTALL-STEP: notice: After: '97'
2019/01/13 09:56:18 - INSTALL-STEP: debug: setStep(): '97'
2019/01/13 09:56:18 - INSTALL-STEP: notice: setStep(): stepError array ( ) < '97'
2019/01/13 09:56:18 - INSTALL-LANGUAGE: info: getLanguage(): en-US
2019/01/13 09:56:18 - INSTALL-LANGUAGE: debug: setLanguage(): en-US
2019/01/13 09:56:18 - INSTALL-THEME: info: getTheme(): modern
2019/01/13 09:56:18 - INSTALL-THEME: info: Checking theme: modern
2019/01/13 09:56:18 - INSTALL-THEME: debug: setTheme(): modern
2019/01/13 09:56:18 - INSTALL-STEP: debug: Error: false
2019/01/13 09:56:18 - INSTALL-STEP: debug: Done: '97'
2019/01/13 09:56:18 - INSTALL-BACKGROUND: debug: backgroundTime = 1547401153.5883
2019/01/13 09:56:18 - INSTALL-BACKGROUND: debug: backgroundNeeded =
2019/01/13 09:56:18 - INSTALL-BACKGROUND: debug: ---------------- Check Expire ----------------
2019/01/13 09:56:18 - INSTALL-BACKGROUND: debug: backgroundDateStarted = 2019-01-13 17:39:13
2019/01/13 09:56:18 - INSTALL-BACKGROUND: debug: backgroundLast = 1547401153.5883
2019/01/13 09:56:18 - INSTALL-BACKGROUND: notice: backgroundLast = 1547401153.5883 (Replaced)
2019/01/13 09:56:18 - INSTALL-BACKGROUND: debug: backgroundExpire = 1547400678
2019/01/13 09:56:19 - INSTALL-JSON: notice:   End: {"Mode":null,"Step":"97","Errors":[],"Eula":"1","Prev":{"Text":"Previous","Step":96,"Enabled":true,"Visible":false},"Next":{"Text":"Next","Step":98,"Enabled":true,"Visible":false},"Test":{"Text":"Test Connection","Step":-4,"Enabled":true,"Visible":false},"Theme":"modern","StepData":{"Current":0,"Total":100}}
@netniV netniV changed the title install fails: cli_test.php incorrectly blocks progress on php path check Installation blocked by PHP CLI environment incorrectly setting $_SERVER values meant only for web Jan 15, 2019
@netniV
Copy link
Member

netniV commented Jan 15, 2019

During our debugging steps, it was identified that various web-based values were being set by PHP, even though the cli_check.php script was being executed via shell_exec() and therefore was a cli not web script.

Input: 23
Output: 529 - cli array ( 
 'SERVER_SIGNATURE' => ''
 'UNIQUE_ID' => 'XDy34TU@Vsp8lRstprdcZQAAANI'
 'HTTP_USER_AGENT' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36'
 'SERVER_PORT' => '80'
 'PHPRC' => '/home/<user>'
 'HTTP_HOST' => 'www.<website>.com'
 'DOCUMENT_ROOT' => ''
 'SCRIPT_FILENAME' => '/home/<user>/public_html/cacti/install/cli_test.php'
 'REQUEST_URI' => '/cacti/install/test.php'
 'SCRIPT_NAME' => '/home/<user>/public_html/cacti/install/cli_test.php'
 'HTTP_CONNECTION' => 'keep-alive'
 'REMOTE_PORT' => '57067'
 'PATH' => '/bin:/usr/bin:/usr/local/php/bin'
 'CONTEXT_PREFIX' => ''
 'PWD' => '/home/<user>/public_html/cacti/install'
 'SERVER_ADMIN' => 'webmaster@<website>.com'
 'REQUEST_SCHEME' => 'http'
 'REDIRECT_STATUS' => '200'
 'HTTP_ACCEPT_LANGUAGE' => 'en-US, en;q=0.9'
 'HTTP_ACCEPT' => 'text/html, application/xhtml+xml, application/xml;q=0.9, image/webp, image/apng, */*;q=0.8'
 'REMOTE_ADDR' => '<client ip>'
 'SHLVL' => '1'
 'SERVER_NAME' => 'www.<website>.com'
 'SERVER_SOFTWARE' => 'CentOS WebPanel: Protected by Mod Security'
 'QUERY_STRING' => ''
 'SERVER_ADDR' => '<internal ip>'
 'GATEWAY_INTERFACE' => 'CGI/1.1'
 'HTTP_UPGRADE_INSECURE_REQUESTS' => '1'
 'SERVER_PROTOCOL' => 'HTTP/1.1'
 'HTTP_ACCEPT_ENCODING' => 'gzip
 deflate'
 'REQUEST_METHOD' => 'GET'
 'HTTP_COOKIE' => 'cacti_remembers=<cookie data>'
 'CONTEXT_DOCUMENT_ROOT' => '/home/<user>/public_html'
 '_' => '/usr/local/bin/php'
 'PHP_SELF' => '/home/<user>/public_html/cacti/install/cli_test.php'
 'PATH_TRANSLATED' => '/home/<user>/public_html/cacti/install/cli_test.php'
 'REQUEST_TIME_FLOAT' => 1547483105.697787
 'REQUEST_TIME' => 1547483105
 'argv' => array ( 0 => '/home/<user>/public_html/cacti/install/cli_test.php'
 1 => '23'
 )
 'argc' => 2
 )
Status: Valid
Command: /usr/local/bin/php -q /home/<user>/public_html/cacti/install/cli_test.php 23

On my CLI, the only things set where:

Web SAPI: apache2handler
Input: 27
Output: 729 - cli array (
'APACHE_RUN_DIR' => '/var/run/apache2'
'APACHE_PID_FILE' => '/var/run/apache2/apache2.pid'
'JOURNAL_STREAM' => '9:42883'
'PATH' => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
'INVOCATION_ID' => '3993224f65764b7d871f10c6443c98c3'
 'APACHE_LOCK_DIR' => '/var/lock/apache2'
'LANG' => 'C'
'APACHE_RUN_USER' => 'www-data'
'APACHE_RUN_GROUP' => 'www-data'
'APACHE_LOG_DIR' => '/var/log/apache2'
'PWD' => '/usr/share/cacti/site/install'
'PHP_SELF' => '/usr/share/cacti/site/install/cli_test.php'
'SCRIPT_NAME' => '/usr/share/cacti/site/install/cli_test.php'
'SCRIPT_FILENAME' => '/usr/share/cacti/site/install/cli_test.php'
'PATH_TRANSLATED' => '/usr/share/cacti/site/install/cli_test.php'
'DOCUMENT_ROOT' => ''
'REQUEST_TIME_FLOAT' => 1547464678.910385
'REQUEST_TIME' => 1547464678
'argv' => array ( 0 => '/usr/share/cacti/site/install/cli_test.php'
 1 => '27'
 )
 'argc' => 2
 )
Status: Valid
Command: /usr/bin/php -q /usr/share/cacti/site/install/cli_test.php 27

A fix for this is currently being tested and committed to develop, then will be tested across multiple OS environments.

@netniV netniV changed the title Installation blocked by PHP CLI environment incorrectly setting $_SERVER values meant only for web Unable to update PHP location during installation due to incorrect CLI environment Jan 15, 2019
netniV added a commit that referenced this issue Jan 15, 2019
This commit corrects a previous unseen issue where the PHP environment at command line level is being populated with environment variables normally only seen when called from a web server.

issue#2304: Installation progress stays at 0%
issue#2311: Unable to update PHP location during installation due to incorrect CLI environment

The new check uses the php_sapi_name() function to verify that we are indeed at 'cli' level.  All other values returned by php_sapi_name are considered non-cli including 'cli-server' which is for client/server scenarios.

Most checks have now been replaced by a single defintion ('CACTI_CLI') to define whether in CLI mode.  If a script is only to be called from CLI it must either defined 'CACTI_CLI_ONLY' or include include/cli_check.php instead of include/global.php.
@netniV
Copy link
Member

netniV commented Jan 15, 2019

The never ending installation is probably the same issue and was reported in #2304

@netniV
Copy link
Member

netniV commented Jan 17, 2019

As part of #2315 I have updated the code to provide better detection of invalid scenario's. If possible, could you update to the latest develop code and see if that works for you?

@netniV netniV added bug Undesired behaviour resolved A fixed issue labels Jan 17, 2019
@JDavidRogers
Copy link
Author

I switched to the develop branch and the install and upgrade process completed successfully! I can now login to the main application again. I'll hunt around and verify that everything is still working well as far as graphs updating, etc.

@JDavidRogers
Copy link
Author

This error showed up in the logs during the upgrade:

2019/01/17 11:06:13 - INSTALL-ERRORS-JSON: debug: array ( '' => array ( 0 => 'Failed to apply specified runtime', ), )
--
2019/01/17 11:06:13 - INSTALL-ERRORS: debug: stepError = 1 -> array ( )
2019/01/17 11:06:13 - INSTALL-ERRORS: info: addError(, Failed to apply specified runtime)

@netniV
Copy link
Member

netniV commented Jan 17, 2019

But that didn't stop the installation? The strange thing is that the step error is 1, which is the welcome screen.

@JDavidRogers
Copy link
Author

JDavidRogers commented Jan 17, 2019

No, the installation went forward without visible issues. Everything seems to be working well, too. Graphs are updating again just fine.

Perhaps the error appeared because the previous upgrade stalled out and was unable to complete?

@netniV
Copy link
Member

netniV commented Jan 17, 2019

Maybe. Not too worried, but I would advise that you set reduce your system logging level if you haven't already done so. Also, run the following to remove the installation debugging as you should hopefully not need it next time:

delete from settings where name like 'log_install%';

If you are happy, go ahead and close the issue.

@JDavidRogers
Copy link
Author

Sounds good. Thanks again for all your help!

@github-actions github-actions bot locked as resolved 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 resolved A fixed issue
Projects
None yet
Development

No branches or pull requests

2 participants