【问题标题】:PHP on Ubuntu AWS Server: POPEN fails with “sh: <command>: not found”Ubuntu AWS 服务器上的 PHP:POPEN 失败并显示“sh: <command>: not found”
【发布时间】:2016-01-15 08:34:06
【问题描述】:

我正在将我当前的网站从 Red Hat 共享服务器转移到 Amazon AWS。当我移动我的工作代码时,我开始在我的 popen 调用中收到一个错误。

错误是:sh: 1: &lt;command&gt;: not found

我在 5 年前发现了一个类似的问题,但从来没有真正好的答案。 popen fails with "sh: <command>: not found"

我在我的 ubuntu 14.04 笔记本电脑上使用 XAMPP 作为本地测试平台,问题没有出现,但它出现在我的 AWS 实例上。在实例上使用带有 php5 和 apache2 的 ubuntu 14.04lts。

我怀疑这可能是 PHP 设置或路径问题,但我尝试的一切都失败了,有什么建议吗?

output = shell_exec('echo abc'); 工作正常。

这里有更多信息:我的代码:

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);

runvariable 基本上是来自 file_exists 的 dkcube,其中包含一些传递变量。第 2 行的回声是

'第 2 行:sh:1:/var/www/html/solver/dkcube:未找到'

希望这可以为您提供更多信息。

我尝试了sudo -H -u php_user sh -c 'content of runvariable here',它返回了同样的错误:sh: 1: /var/www/html/solver/dkcube: not found

【问题讨论】:

  • “我尝试的一切都失败了” 你到底尝试了什么?它究竟是如何失败的?例如,$output = shell_exec('echo abc'); 有效吗?
  • 如果你手动运行sudo -H -u php_user sh -c 'content of runvariable here'会发生什么?

标签: php amazon-web-services ubuntu-14.04 popen


【解决方案1】:

感谢 J.F Sebastian 的事实调查问题,他给了我解决问题所需的花絮。使用他的sudo -H -u php_user sh -c 'content of runvariable here' 问题,我确定这是一个 ubuntu 问题而不是 php 问题。

我的问题的根本原因是我在 64 位操作系统上运行 32 位可执行文件,并且没有为我的可执行文件安装正确的库。

首先,我必须将 sh 从 dash 更改为 bash,如下所述:source command not found in sh shell

然后我必须安装正确的库,如下所述:https://unix.stackexchange.com/questions/75054/ldd-tells-me-my-app-is-not-a-dynamic-executable

【讨论】:

    猜你喜欢
    • 2011-02-12
    • 1970-01-01
    • 1970-01-01
    • 2019-07-01
    • 2020-09-26
    • 2022-12-25
    • 2015-12-02
    • 2016-02-24
    • 2022-12-10
    相关资源
    最近更新 更多