【问题标题】:php not able to execute system commandsphp无法执行系统命令
【发布时间】:2011-11-27 21:16:04
【问题描述】:

由于某种原因,以下 php 脚本在通过 apache 调用时没有返回结果... php.ini 中是否有系统安全设置允许系统命令?

<div style="background:#000;color:#fff">
<?php

   $cmd = "/bin/date";
   $output = system($cmd);
   printf("System Output: $output\n");
   exec($cmd, $results);
   printf("Exec Output: {$results[0]}\n");
   echo"<pre>";
   echo system('/bin/ls');
   echo"</pre>";
   ?>
   </div>

【问题讨论】:

  • 我检查了 php.ini,disable_functions= 为空。
  • 什么都不返回? system´ or exec` 还是两者兼而有之?
  • 既不......系统也在plesk上...... :)
  • 您应该首先查看与您类似的问题(请参阅右侧的 Realated 列,顶部有一个搜索框)。这些命令“不起作用”的原因可能有很多(实际上它们起作用,但它们没有达到您的预期 - 但它们工作正常!)。还要考虑如何调试问题(您的代码看起来已经开始调试)。此外,请联系您的系统管理员,她/他也应该能够为您提供帮助。并启用PHP报错,还有安全模式等。
  • 看来安全模式已开启...通过 phpinfo.php。有谁知道如何在plesk中关闭安全模式?在 php.ini 它说安全模式关闭...

标签: php shell exec


【解决方案1】:

您的主机(或配置)可能正在限制 system() 或 exec() 命令。检查您的配置或联系您的主机

; This directive allows you to disable certain functions for security reasons.
; It receives a comma-delimited list of function names. This directive is
; *NOT* affected by whether Safe Mode is turned On or Off.
; http://php.net/disable-functions
disable_functions =

应该是空白的,在我的机器上工作

http://sandbox.phpcode.eu/g/e47f7

另外,检查 SElinux 和 Suhoshin 是否配置正确

【讨论】:

  • 各位,selinux 被禁用了……这是怎么回事?
  • 还看到 sh: /date: 没有这样的文件或目录 sh: /date: 没有这样的文件或目录 sh: /ls: 在 apache 日志中没有这样的文件或目录
【解决方案2】:

plesk 安全模式...在 httpd.include 中禁用...叹息...当系统落在您的膝上时喜欢它

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-04-16
    • 1970-01-01
    • 2021-09-07
    • 1970-01-01
    • 1970-01-01
    • 2011-10-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多