2012-12-06 20:45

1932人阅读

评论(0)

往往在调用system、exec 等函数时,要么没有反应,要么出错:

原因很多,以下是抄别人的:

====================================================================================

错误分析:

1、Warning: system() has been disabled for security reasons

该错误是由于服务器安全配置将system函数关闭了,编辑php.ini查找 disable_functions 将等号后面的 system 去掉即可。

2、Warning: system() [function.system]: Unable to fork

该错误是由于当前站点的运行帐号无法访问cmd.exe,找到windows\system32\cmd.exe 属性,安全,添加当前站点的运行帐号权限,或 users组权限即可。

3、在web访问下执行没有任何响应也不报错,使用php cli命令行执行却可以正常返回结果

该错误一般由于WINDOWS系统路径引起,你的程序中大概使用了绝对路径去访问程序比如:

system('D:\server\DLL\IECapt.exe --url=http://tech.cncms.com --out="D:\web\tt.fei.cn\htdocs\ttt\tech.png"');

此时用命令行执行结果OK,但用WEB访问就是空白也没错误。

修正方法,将文件的访问路径改为相对即可:

将IECapt.exe 复制到你的站点程序当前目录下,并将代码改为:

system('IECapt.exe --url=http://www.baidu.com --out=t/tech.png');

再次访问页面,OK,结果出来了。

====================================================================================

但是当我在执行的时候:

system("/sbin/ifconfig

>/home/ago/Desktop/webshell.log",$retval);  // return 2   Misuse of

shell builtins (according to Bash documentation)

system("ifconfig >/home/ago/Desktop/webshell.log",$retval);            // return 127  "command not found"

网上找了很多教程和解决办法:

要写文件的话,确保有权限操作文件夹

I am using this php code:

exec("unrar e file.rar",$ret,$code);

and getting an error code of illegal command ie 127

... but when I am using this command through ssh its working ...

because unrar is installed on the server ... so can anyone guess why exec is not doing the right stuff?

=====================================================================

Try using the direct path of the application (/usr/bin/unrar of whatever), it sounds like php can't find the application

=====================================================================

If you have chrooted apache and php, you will also want to put /bin/sh into the chrooted environment. Otherwise, the exec() or passthru() will not function properly, and will produceerror code 127, file not found.

=====================================================================

I found the problem. The problem was my security-paranoid OpenBSD. When upgrading from 3.1 to 3.2 they added:

Apache runs chroot'd by default. To disable this, see the new -u option.

The chroot prevented Apache from accessing anything outside of a

directory, so I moved everything into the apache directory including

netpbm. Everything was accessible and executable, but I guess it was

still in some sort of "safe mode" because the exec() always

returned 127.

Anyway, running httpd with the -u option went back to the less secure non chroot'd apache startup, which allowed the exec() to work again.

=====================================================================

ERROR-CODE

Linux        http://tldp.org/LDP/abs/html/exitcodes.html#EXITCODESREF

http://www.linuxtopia.org/online_books/advanced_bash_scripting_guide/exitcodes.html

windows        http://www.hiteksoftware.com/knowledge/articles/049.htm

=====================================================================

"Remember to use the full path (IE '/usr/local/bin/foo' instead of

'foo') when using passthru, otherwise you'll get an exit code of 127 (command not found).

Remember, you'll also get this error if your file does not have executable permission."

"If you have chrooted apache and php, you will also want to put /bin/sh into the chrooted environment. Otherwise, the exec() or passthru() will not function properly, and will produce error code 127, file not found."

=====================================================================

环境:PHP+linux下的apache2

php中的exec函数可以执行很多命令(脚本)使用比较方便,但是在linux下需要给与权限。修改/etc/sudoer文件,做两处改动:

1)

在文件中添加apache的用户,我用的apache2的用户名是www-data,有的是daemon、httpd等(查看一下自己的apache的配

置文件即可)。添加的格式:www-data ALL=(ALL) NOPASSWD: ALL(格式在/etc/sudoer文件中有,使用

visudo)。

2)

注释掉default requiretty.(大部分时候,exec不能正确执行都是由这一行没有注释掉引起的)

后记:之所以发文是因为每次总是忘记了第二条。导致在网上搜索,不过好像没有人真正解释过。希望此文能提醒自己,帮助别人吧。......

============================================================================================

因为sudo配置信息必须保证php网页执行用户(我这里是apache)具备合适的权限执行svn 命令。

为此,修改sudo配置文件,直接键如visudo命令编辑配置文件:

1. 注释Defaults requiretty

Defaults requiretty修改为 #Defaults requiretty, 表示不需要控制终端。

否则会出现sudo: sorry, you must have a tty to run sudo

2. 增加行 Defaults visiblepw

否则会出现 sudo: no tty present and no askpass program specified

3. 赋予apache用户执行svn权限

如,增加行:apache ALL=(ALL) NOPASSWD: /usr/bin/svn

注:NOPASSWD可以使在命令执行时不需要交互输入apache用户的密码

============================================================================================

再试了各种方法之后,发现都不行,最后我把网站根目录从 /var/www迁移到了/home/test ,下面,竟然莫名就好了,sudoer文件都没有修改

php system 执行失败,PHP 执行 system、exec 等函数发生错误相关推荐

  1. c# System.Net.WebException: 基础连接已经关闭: 发送时发生错误。

    本文介绍了C#System.Net.WebException:基础连接已关闭:发送时发生意外错误 -> System.IO.IOException: 无法从传输连接中读取数据: 远程主机强迫关闭 ...

  2. php system 执行失败,php执行system()函数没有任何反应

    浏览量: 361 引言 最近需要用php调用本地Linux命令,来实现一些功能. 在网上搜了一下发现,PHP提供4个专门的执行外部命令的函数:exec(), system(), passthru(), ...

  3. 2021/8/11 火狐浏览器报错 建立安全连接失败 连接到 www.baidu.com 时发生错误。您正试图导入一个与已存在证书相同颁发者和序列号但却不相同的证书。错误代码SEC_ERROR_REU

    图是后配的,因为第一次写csdn,开始没想记录下来,所以没有图片,但是是含义相同的提示信息. 以下是网络上大多的解决方法,不仅不对,还没说清楚,屁用没有. 1.点击菜单按钮  并点击 选项 按钮 2. ...

  4. exec族函数、system函数、popen函数、PATH

    exec族函数函数的作用: 我们用fork函数创建新进程后,经常会在新进程中调用exec函数去执行另外一个程序.当进程调用exec函数时,该进程被完全替换为新程序(在exec都后面的代码不会被得到执行 ...

  5. linux ora27040,AnyBackup-Oracle 异机恢复任务失败,执行输出提示 ORA-00344、ORA-27040 错误...

    关键字 ORA-00344.ORA-27040 适用产品 AnyBackup 5.0.x AnyBackup 6.0.x 超易备 5.0.x 问题描述 在使用 AnyBackup 进行 Oracle ...

  6. 2022-10-11(一、远程命令执行和系统命令执行)

    文章目录 命令执行 原理 危害 RCE 管道符号 远程执行常用`函数` 执行系统命令: 代码执行与加密: 文件包含与生成: PHP代码执行函数 敏感文件 例子 加固 参考 命令执行 命令执行漏洞是指攻 ...

  7. Linux进程之exec镞函数的介绍(execl, execlp, execle, execv, execvp, execvpe)

    exec族函数函数的作用: 我们用fork函数创建新进程后,经常会在新进程中调用exec函数去执行另外一个程序.当进程调用exec函数时,该进程被完全替换为新程序.因为调用exec函数并不创建新进程, ...

  8. Linux进程 exec族函数(execl,execlp,execle,execv,execvp,execcvpe)

    exec族函数的作用 我们用fork函数创建新进程后,经常会在新进程中调用exec函数去执行另外一个程序.当进程调用exec函数时,该进程被完全替换为新程序.因为调用exec函数并不创建新进程,所以前 ...

  9. Maven执行mvn help:system命令失败的特殊原因解决思路

    maven安装成功,但是执行mvn help:system命令却总是出现问题,在网上查找了各种资料,花费了大量时间,始终都没有成功,最后通过百度网盘下载资料到自己定义的maven本地仓库时发现,出现了 ...

最新文章

  1. 适合计算机应用的班群名称,班级同学群名字大全
  2. IT人的自我导向型学习:学习的1个理念和2个心态
  3. x86汇编-2(第五章)nasm汇编基础知识、指令、显存、bochs调试
  4. http-helloworld
  5. java算术运算符的分类_6.Java算术运算符
  6. 1.1zookeeper简介
  7. dom4j解析xml获取所有的子节点并放入map中
  8. java如何给数字每三位加一个逗号_将每三个数字加上逗号处理Java代码
  9. webstorm快捷键大全
  10. dbf转成excel_怎么样把dbf文件转换成excel/dbf转excle
  11. Scala编译后的class文件反编译的结果
  12. 嵊州D4T1 翻车 rollover 真的翻车了
  13. ubuntu安装firefox flash插件
  14. C++类和对象——设计一个长方形类
  15. php+矩阵,PHP实现简单矩阵算法
  16. 电磁感应、电感与变压器
  17. Qt-使用QString输出数字上标(不要再用x2或x^2表示平方啦)
  18. sql查询记录数大于1
  19. 订单部分商品退款模型思考
  20. 深度评测 Amazfit跃我GTR 3 Pro 和小米color 2选哪个

热门文章

  1. 两个Oracle JDK的故事
  2. spring框架mvc框架_Spring的MVC测试框架入门–第1部分
  3. 功能Java示例 第3部分–不要使用异常来控制流程
  4. 使用Spring @Transactional进行数据源路由
  5. Maven常见问题和陷阱
  6. JavaFX中的塔防(6)
  7. 窥探JBoss Fuse 6.1的新功能
  8. Java:本地最小语言
  9. 如何用正则表达式杀死Java
  10. Tomcat的带有守护程序和关闭挂钩的正常关闭