1

I am moving my current website over to Amazon AWS from a Red Hat shared server. When I moved my working code, I started to receive an error in my popen call.

The error is: sh: 1: <command>: not found

I found a similar question 5 years ago but there was never really a good answer. popen fails with "sh: <command>: not found"

I use XAMPP on my ubuntu 14.04 laptop for a local testbed and the problem does not arise there, but it does on my AWS instance. Using ubuntu 14.04lts with php5 and apache2 on the instance.

I suspect it might be a PHP setting or path problem but everything I tried has failed, any suggestions?

output = shell_exec('echo abc'); worked fine.

Here is some more info: My Code:

if (file_exists(SitePATH."/solver/dkcube")){
    //echo "Executable is there <br />"; 
    error_reporting(E_ALL); 
    $handle = popen("$runvariable 2>&1","r"); 
    echo "Line 1: '$handle'; ".gettype($handle). "<br />"; 
    $contents = stream_get_contents($handle); 
    echo "Line 2: $contents"; pclose($handle);

The runvariable is basically the dkcube from the file_exists with some pass through variables. The echo for Line 2 is

'Line 2: sh: 1: /var/www/html/solver/dkcube: not found'

Hopefully that gives you some more info.

I tried the sudo -H -u php_user sh -c 'content of runvariable here' and it returned the same error: sh: 1: /var/www/html/solver/dkcube: not found

Community
  • 1
  • 1
DAK
  • 21
  • 4
  • *"everything I tried has failed"* what exactly have you tried? and how exactly does it fail? For example, does `$output = shell_exec('echo abc');` work? – jfs Oct 16 '15 at 15:43
  • what happens if you run `sudo -H -u php_user sh -c 'content of runvariable here'` manually? – jfs Oct 18 '15 at 10:53

1 Answers1

1

Thanks to J.F Sebastian's fact finding questions, he gave me the tidbit I needed to solve my problem. Using his sudo -H -u php_user sh -c 'content of runvariable here' question, I determined that it was a ubuntu problem not a php problem.

The root cause of my problem was I was running a 32-bit executable on a 64 bit operating system and did not have the correct libraries for my executable installed.

First I had to change the sh from dash to bash as outlined here: source command not found in sh shell

Then I had to install the right libraries as outlined here: https://unix.stackexchange.com/questions/75054/ldd-tells-me-my-app-is-not-a-dynamic-executable

Community
  • 1
  • 1
DAK
  • 21
  • 4