PHP did not return expected result / File not found

Post general support questions here that do not specifically fall into the Linux or Windows categories.

Moderators: Moderators, Developers

Author
Message
Comenius
Posts: 15
Joined: Sun Jul 24, 2016 11:28 am

PHP did not return expected result / File not found

#1 Post by Comenius » Fri Jan 11, 2019 7:19 pm

I'm trying to upgrade a 1.1.38 installation to 1.2.0. Using the install wizard goes fine until step 5, when binary paths are checked. I'm getting a "PHP did not return expected result" error on the PHP binary path. I have /usr/local/bin/php entered which is definitely correct. No errors are showing up in Apache's error log or Cacti's log. I'm running PHP 5.6.39 and Apache/2.4.37 (Unix).

Any idea how I can move forward?

Code: Select all

[~]$ which php
/usr/local/bin/php

Code: Select all

$ /usr/local/bin/php --version
PHP 5.6.39 (cli) (built: Jan 11 2019 13:30:10)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies

Code: Select all

[~]$ /usr/local/apache/bin/httpd -v
Server version: Apache/2.4.37 (Unix)
Server built:   Jan 11 2019 16:39:42
Attachments
2019-01-11_16-15-20.png
2019-01-11_16-15-20.png (57.72 KiB) Viewed 1466 times
Last edited by Comenius on Fri Jan 11, 2019 8:18 pm, edited 1 time in total.

netniV
Cacti Guru User
Posts: 2795
Joined: Sun Aug 27, 2017 12:05 am

Re: PHP did not return expected result

#2 Post by netniV » Fri Jan 11, 2019 8:13 pm

That was a check that I put in to ensure that when Cacti runs a PHP file it runs as expected. If you are seeing that message it means that the returned result from running an external script was not purely the expected result.

Run the following SQL statement, then message me privately with the install-complete.log that will be generated when you next run through the installer.

Code: Select all

SELECT * FROM Settings WHERE name = 'log_verbosity'
REPLACE INTO Settings ('log_install','5');
REPLACE INTO Settings ('log_verbosity','5');
Once you have finished, and sent me the log file, restore your settings by running the following:

Code: Select all

DELETE FROM Settings where name = 'log_install';
REPLACE INTO Settings ('log_verbosity','<value from first statement>');

Comenius
Posts: 15
Joined: Sun Jul 24, 2016 11:28 am

Re: PHP did not return expected result / File not found

#3 Post by Comenius » Fri Jan 11, 2019 8:22 pm

Before I saw your message I manually changed the PHP path in the database to /usr/local/bin/php

It had previously been /bin/php under 1.1.38 which had run successfully for over a year.

With /usr/local/bin/php in the database I'm now getting a "File not found" error instead. Progress? :D

Would you still like me to run the commands from your previous message?
Attachments
2019-01-11_17-17-28.png
2019-01-11_17-17-28.png (55.9 KiB) Viewed 1468 times

Comenius
Posts: 15
Joined: Sun Jul 24, 2016 11:28 am

Re: PHP did not return expected result / File not found

#4 Post by Comenius » Fri Jan 11, 2019 8:40 pm

I made the database changes you requested and have the install-complete.log file but unfortunately it appears I don't yet have permissions to send a private message to you.

Is there some other way for me to get the log file to you?

Also, in case it matters, I'm running MariaDB 10.1.37.

Code: Select all

[~]$ /usr/bin/mysql --version
/usr/bin/mysql  Ver 15.1 Distrib 10.1.37-MariaDB, for Linux (x86_64) using readline 5.1


Comenius
Posts: 15
Joined: Sun Jul 24, 2016 11:28 am

Re: PHP did not return expected result / File not found

#6 Post by Comenius » Sat Jan 12, 2019 8:31 am

I just sent you the log file via email.

Thanks for your help!

User avatar
Osiris
Cacti Pro User
Posts: 841
Joined: Mon Jan 05, 2015 10:10 am

Re: PHP did not return expected result / File not found

#7 Post by Osiris » Sat Jan 12, 2019 2:40 pm

This might be some web server permission issue too. If you open a shell and run the following, see if you get what you expect:
php -q install/cli_check.php 2
You should get 4 back. Also, check your apache error log for anything odd.
Before history, there was a paradise, now dust.

Comenius
Posts: 15
Joined: Sun Jul 24, 2016 11:28 am

Re: PHP did not return expected result / File not found

#8 Post by Comenius » Sat Jan 12, 2019 3:19 pm

I don't have a cli_check.php file in my cacti/install directory, although there is a cli_test.php file.

Running that file gives an output of 4, as expected:

Code: Select all

$ php -q ./cli_test.php 2
$ 4
No errors are presents in the Apache error log, just the entries from the last time Apache was started.

Code: Select all

[Fri Jan 11 16:48:09.681684 2019] [mpm_event:notice] [pid 23450:tid 139799359735680] AH00492: caught SIGWINCH, shutting down gracefully
[Fri Jan 11 16:48:10.015387 2019] [:notice] [pid 24376:tid 140523359012736] ModSecurity for Apache/2.9.1 (http://www.modsecurity.org/) configured.
[Fri Jan 11 16:48:10.015457 2019] [:notice] [pid 24376:tid 140523359012736] ModSecurity: APR compiled version="1.6.2"; loaded version="1.6.2"
[Fri Jan 11 16:48:10.015462 2019] [:notice] [pid 24376:tid 140523359012736] ModSecurity: PCRE compiled version="8.32 "; loaded version="8.32 2012-11-30"
[Fri Jan 11 16:48:10.015466 2019] [:notice] [pid 24376:tid 140523359012736] ModSecurity: LIBXML compiled version="2.9.1"
[Fri Jan 11 16:48:10.015469 2019] [:notice] [pid 24376:tid 140523359012736] ModSecurity: Original server signature: Apache/2.4.37 (Unix)
[Fri Jan 11 16:48:10.015472 2019] [:notice] [pid 24376:tid 140523359012736] ModSecurity: Status engine is currently disabled, enable it by set SecStatusEngine to On.
[Fri Jan 11 16:48:10.255971 2019] [mpm_event:notice] [pid 24377:tid 140523359012736] AH00489: Apache/2.4.37 (Unix) CentOS WebPanel: Protected by Mod Security configured -- resuming normal operations
[Fri Jan 11 16:48:10.256015 2019] [core:notice] [pid 24377:tid 140523359012736] AH00094: Command line: '/usr/local/apache/bin/httpd'
[Sat Jan 12 03:08:05.597122 2019] [mpm_event:notice] [pid 24377:tid 140523359012736] AH00493: SIGUSR1 received.  Doing graceful restart
[Sat Jan 12 03:08:05.901891 2019] [mpm_event:notice] [pid 24377:tid 140523359012736] AH00489: Apache/2.4.37 (Unix) CentOS WebPanel: Protected by Mod Security configured -- resuming normal operations
[Sat Jan 12 03:08:05.901919 2019] [core:notice] [pid 24377:tid 140523359012736] AH00094: Command line: '/usr/local/apache/bin/httpd'

netniV
Cacti Guru User
Posts: 2795
Joined: Sun Aug 27, 2017 12:05 am

Re: PHP did not return expected result / File not found

#9 Post by netniV » Sat Jan 12, 2019 5:59 pm

Did the response include the $ sign because that seems wrong?

Looking at the log file, it tried to use it's default location and found that was wrong. You changed that, and it accepted that it was in the correct place, but it didn't get the response it was expecting. I partially suspect that may well apparmour or selinux is getting in the way based off the above logs. To test that, save the following to the install folder as test.php (eg, <cacti>/install/test.php):

Code: Select all

<?php
include('../include/global.php');

$path = '/usr/local/bin/php';
$input = mt_rand(2,64);
$cmd =  $path . ' -q ' . $config['base_path'] .
        '/install/cli_test.php ' . $input;
$output = shell_exec($cmd);

$expected = $input * $input;
$status = ($output != $input * $input) ? 'Invalid' : 'Valid';
echo "<html><body><h1>Input: $input<br>Output: $output<br>Status: $status<br>Command: $cmd</h1></body></html>";
Then browse to http://<cacti>/install/test.php and post the results and check your apache/cacti error logs.

At the end of the day, I have to believe that the code is correct or we would have seen a lot of this issue. It's a basic installation check that occurs and it's not a complex one. It merely doubles multiples the input by itself and returns the result so the installation code can verify that execution of php files will work. It stops people from crippling cacti by pointing it at an invalid location of PHP.

Comenius
Posts: 15
Joined: Sun Jul 24, 2016 11:28 am

Re: PHP did not return expected result / File not found

#10 Post by Comenius » Sat Jan 12, 2019 8:00 pm

Yes, the $ is just my command prompt. You can ignore it.

Here's the output of the test page.

Code: Select all

Input: 7
Output: 
This script is only meant to run at the command line.
Status: Invalid
Command: /usr/local/bin/php -q /home/blah/public_html/cacti/install/cli_test.php 7
Nothing is showing up in the Apache error log or the Cacti error log.

Is the output "This script is only meant to run at the command line." expected behavior when running test.php from a web browser?

Running the command from the test.php script from the command line does not show errors and produces the correct results.

Code: Select all

$ /usr/local/bin/php -q /home/blah/public_html/cacti/install/cli_test.php 7
49
$
Where exactly in the code is the PHP check that is failing happening? Perhaps I can take a look as well...

Is that PHP check code new to 1.2.0, or was it also in 1.1.38?

Also... curious... What version of PHP are you using to test? Has the code been explicitly tested against PHP 5.6.39?

Sorry for the hassle... Very much appreciate your help! :D

User avatar
Osiris
Cacti Pro User
Posts: 841
Joined: Mon Jan 05, 2015 10:10 am

Re: PHP did not return expected result / File not found

#11 Post by Osiris » Sat Jan 12, 2019 8:33 pm

Remove mod-security and restart Apache and problem solved.
Before history, there was a paradise, now dust.

User avatar
Osiris
Cacti Pro User
Posts: 841
Joined: Mon Jan 05, 2015 10:10 am

Re: PHP did not return expected result / File not found

#12 Post by Osiris » Sat Jan 12, 2019 8:34 pm

Once you get the hang of it, you can write some mod-security rules for cacti. Not a priority for me for sure.
Before history, there was a paradise, now dust.

Comenius
Posts: 15
Joined: Sun Jul 24, 2016 11:28 am

Re: PHP did not return expected result / File not found

#13 Post by Comenius » Sat Jan 12, 2019 8:54 pm

Hah, if only it were that easy... 8)

Unfortunately I've tried uninstalling ModSecurity and restarting Apache without any improvement.

netniV
Cacti Guru User
Posts: 2795
Joined: Sun Aug 27, 2017 12:05 am

Re: PHP did not return expected result / File not found

#14 Post by netniV » Sun Jan 13, 2019 11:25 am

In the install/cli_test.php file, can you separate out the three IF statements so we can identify which one is triggering that message. You should not be seeing that message at all.

Code: Select all

if (!isset($_SERVER['argv'][0]) || isset($_SERVER['REQUEST_METHOD'])  || isset($_SERVER['REMOTE_ADDR'])) {
        die('<br><strong>This script is only meant to run at the command line.</strong>');
}

Code: Select all

if (!isset($_SERVER['argv'][0])) {
        die('<br><strong>ERROR 1 - This script is only meant to run at the command line.</strong>');
} elseif (isset($_SERVER['REQUEST_METHOD']) {
        die('<br><strong>ERROR 2 - This script is only meant to run at the command line.</strong>');
} else if (isset($_SERVER['REMOTE_ADDR'])) {
        die('<br><strong>ERROR 3 - This script is only meant to run at the command line.</strong>');
}
Then run the test.php again and let me know which is the issue.

Comenius
Posts: 15
Joined: Sun Jul 24, 2016 11:28 am

Re: PHP did not return expected result / File not found

#15 Post by Comenius » Sun Jan 13, 2019 11:56 am

I made the changes to cli_test.php per your instructions, and strangely, it appears as if neither of those 3 items is triggering the error message. The "This script is only meant to run at the command line." message is now missing. If I revert back to the original file, though, that error message reappears. Strange! :o Here's the output from the modified file:

Code: Select all

Input: 56
Output: 
Status: Invalid
Command: /usr/local/bin/php -q /home/blah/public_html/cacti/install/cli_test.php 56
For reference, and just to make sure I fully understood your directions, this is the full modified cli_test.php file:

Code: Select all

#!/usr/bin/php -q
<?php
/*
 +-------------------------------------------------------------------------+
 | Copyright (C) 2004-2018 The Cacti Group                                 |
 |                                                                         |
 | This program is free software; you can redistribute it and/or           |
 | modify it under the terms of the GNU General Public License             |
 | as published by the Free Software Foundation; either version 2          |
 | of the License, or (at your option) any later version.                  |
 |                                                                         |
 | This program is distributed in the hope that it will be useful,         |
 | but WITHOUT ANY WARRANTY; without even the implied warranty of          |
 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           |
 | GNU General Public License for more details.                            |
 +-------------------------------------------------------------------------+
 | Cacti: The Complete RRDtool-based Graphing Solution                     |
 +-------------------------------------------------------------------------+
 | This code is designed, written, and maintained by the Cacti Group. See  |
 | about.php and/or the AUTHORS file for specific developer information.   |
 +-------------------------------------------------------------------------+
 | http://www.cacti.net/                                                   |
 +-------------------------------------------------------------------------+
*/

/* do NOT run this script through a web browser */
if (!isset($_SERVER['argv'][0])) {
        die('<br><strong>ERROR 1 - This script is only meant to run at the command line.</strong>');
} elseif (isset($_SERVER['REQUEST_METHOD']) {
        die('<br><strong>ERROR 2 - This script is only meant to run at the command line.</strong>');
} else if (isset($_SERVER['REMOTE_ADDR'])) {
        die('<br><strong>ERROR 3 - This script is only meant to run at the command line.</strong>');
}

if ($argv !== false && sizeof($argv)) {
	$value = intval($argv[1]);
	print $value * $value;
}
And this is the full test.php file:

Code: Select all

<?php
include('../include/global.php');

$path = '/usr/local/bin/php';
$input = mt_rand(2,64);
$cmd =  $path . ' -q ' . $config['base_path'] .
        '/install/cli_test.php ' . $input;
$output = shell_exec($cmd);

$expected = $input * $input;
$status = ($output != $input * $input) ? 'Invalid' : 'Valid';
echo "<html><body><h1>Input: $input<br>Output: $output<br>Status: $status<br>Command: $cmd</h1></body></html>";

Post Reply