如何调试 exec() 问题? [英] How can I debug exec() problems?

查看:18
本文介绍了如何调试 exec() 问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

exec 命令在我的服务器上不起作用,它没有做任何事情,我已经关闭了 safe_mode,并验证了所有控制台命令都在工作,我已经尝试过使用绝对路径.我已经检查了应用程序的权限,我需要的所有应用程序都具有执行权限.我不知道还能做什么,这是我尝试过的代码的概要.

The exec command doesn't work on my server, it does not do anything, I've had safe_mode off, and verified that all the console commands are working, I've tried with absolute paths. I've checked the permissions on the applications and all the applications I need have execution permissions. I don't know what else to do, here are the rundown of the codes I've tried.

echo exec('/usr/bin/whoami');

echo exec('whoami');

exec('whoami 2>&1',$output,$return_val);
if($return_val !== 0) {
    echo 'Error<br>';
    print_r($output);   
}

exec('/usr/bin/whoami 2>&1',$output,$return_val);
if($return_val !== 0) {
    echo 'Error<br>';
    print_r($output);   
}

最后两个代码显示:

Error
Array ( )

我联系了服务器服务,他们帮不了我,他们不知道为什么 exec 命令不起作用.

I've contacted the server service and they can't help me, they don't know why the exec command isn't working.

推荐答案

看看/etc/php.ini,有下:

; 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://www.php.net/manual/en/ini.sect.safe-mode.php#ini.disable-functions
disable_functions =

确保 exec 没有像这样列出:

make sure that exec is not listed like this:

disable_functions=exec

如果是这样,删除它并重新启动apache.

If so, remove it and restart the apache.

为了方便调试,我通常喜欢手动执行php文件(可以请求更多错误而不在主ini中设置).为此添加标题:

For easy debugging I usually like to execute the php file manually (Can request more errors without setting it in the main ini). to do so add the header:

#!/usr/bin/php
ini_set("display_errors", 1);
ini_set("track_errors", 1);
ini_set("html_errors", 1);
error_reporting(E_ALL);

到文件的开头,使用chmod +x myscript.php赋予它权限并执行它./myscript.php.这是非常谨慎的,尤其是在繁忙的服务器上,会向日志文件写入大量内容.

to the beginning of the file, give it permissions using chmod +x myscript.php and execute it ./myscript.php. It's very heedful especially on a busy server that write a lot to the log file.

编辑

听起来像是权限问题.创建一个执行诸如 echo "helo world" 之类的简单操作的 bash 脚本并尝试运行它.确保您对文件和包含文件的文件夹具有权限.你可以做 chmod 755 只是为了测试.

Sounds like a permissions issue. Create a bash script that does something simple as echo "helo world" and try to run it. Make sure you have permissions for the file and for the folder containing the file. you chould just do chmod 755 just for testing.

这篇关于如何调试 exec() 问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆