Linux – Wrong version of PHP is used when called from a script

apache-2.2linuxPHPredhat

I apologize ahead of time if this question is really basic. My background is in Windows and I am being asked to maintain a RedHat Linux server that is in bad shape and is in production use.

The issue is that the version of PHP is different when executed from a script in Apache vs. the command line.

For example:

From the command line:

enter image description here

From the web page (Apache):

enter image description here

From the a php script called by a web page:

enter image description here

The script is called by this php code and function:

$exec_result = sku_exec(CLIMPORT.FILE_NAV, '', $_POST['nav_skus']);

function sku_exec($file_path, $call, $args)
{
    $exe = $file_path.' ';
    if($call != '' && isset($call) && $call) $exe .= $call.' ';
    $exe .= $args;
//  echo $exe.'<hr />';
    exec('php '.$exe, $return_data);
    return $return_data;
}

I need to downgrade the script to use 5.2.9 instead of 5.4.1.

Where do I even start to look for how this is configured? Why would the version of PHP that Apache is using be different from the version that it is calling from a script?

I looked at Apache’s config file but did not see anything that jumped out at me.

Any suggestions?

Unfortunately, upgrading the server to the latest PHP is not an option at the moment. The plan is to build out a new server and migrate to it.

Best Answer

Run which php from CLI and add the path to the script so that you are running exec('/path/to/the/cli/php. Should your user be so restricted to not be able to run which (that'd be seriously messed up): the user running the command line has a different environment and so a different PATH to what the user has. The PATH variable, if I remember correctly although it was long ago, exists even in DOS. So take the values in PATH (echo $PATH) and manually check which dir contains a file called php. That's what which does, anyways.

You badly need to read some basic Linux book if this is now your job.