如何更改外壳为PHP的EXEC() [英] How do I change the shell for php's exec()

查看:72
本文介绍了如何更改外壳为PHP的EXEC()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用PHP的exec()函数在Ubuntu服务器上。
问题是,我送花儿给人得到一个错误,该命令没有找到。例如使用

  EXEC(回声123);

打印


  

SH:/回声:找不到


对我来说,它看起来像PHP是使用sh的外壳,当我想使用bash是。
我试图改变在/ etc / passwd文件WWW的数据的外壳,这并没有帮助。

没有任何人有一个想法,还有什么地方的问题可能是来自或我如何更改PHP的Ubuntu的用户的shell。

谢谢,蒂莫


这也许可以帮助:

我叫bash脚本从ssh作为蒂莫,这个脚本调用PHP脚本,它使用EXEC。我知道,这听起来有些不可思议,但它是一个更大的开发环境的一部分...

问题的关键是,我不能永远肯定,作为用户在执行内部Exec中的脚本。


现在我想通了,必须有参与其他版权问题。
即使我尝试调用一个bash脚本test.sh(由它的完整路径!)从EX​​EC内,PHP test.php的只想说。


  

上海:/test.sh:找不到



解决方案

尝试了shell_exec()代替。 EXEC不应该以任何shell执行程序。或者,你可以调用的bash像

EXEC

 执行exec(/斌/ bash的-c \\回声$ foo的>跳回到bar.txt'\\)

I want to use php's exec() function on an ubuntu server. The problem is, I alway get an error, that the command is not found. For example using

exec("echo 123");

prints

sh: /echo: not found

To me, it looks like php is using the sh shell, when I want to be using bash. I tried changing the shell for www-data in /etc/passwd, that didn't help either.

Does anybody have an idea where else the problem might be coming from or how I can change the shell for php's ubuntu user.

Thanks, Timo


[EDIT]

Maybe this helps:

I call a bash script from ssh as timo, this script calls a php script, which uses exec. I know, it sounds weird, but it's part of a bigger development environment...

The point is, I'm not ever certain, as which user the script inside exec is executed.


[EDIT]

By now I figured out that there must be another rights problem involved. Even if I try calling a bash script test.sh (by it's full path!) from within exec, php test.php will just say.

sh: /test.sh: not found

解决方案

Try shell_exec() instead. exec should not invoke ANY shell to execute your program. Alternately, you can invoke bash with exec like

exec("/bin/bash -c \"echo $foo > bar.txt'\"")

这篇关于如何更改外壳为PHP的EXEC()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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