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

查看:63
本文介绍了如何调试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天全站免登陆