任何想法,为什么我可以从命令行执行命令,但不能从PHP exec()执行 [英] Any idea why I can execute command from Command Line but not From PHP exec()
问题描述
好,
我进行了一些创造性的搜索,有点遇到障碍.
I have done some creative searches and am kind of hitting a road block.
我正在尝试使用Linux程序"sox".我正在尝试从我的PHP脚本中调用它.如果我使用命令行,则脚本可以正常工作.但是,当我使用PHP exec时,它不起作用.
I am trying to use the linux program "sox." I am trying to call it from my PHP script. The script DOES work if I use the command line. However, when I use PHP exec, it does not work.
示例:
sox file1.mp3 file2.mp3 tempfile.mp3 -V3
("V3"指定详细输出)
("V3" specifies a verbose output)
在命令行中以用户X"或root身份执行时,我可以创建新文件.但是,当我以以下方式执行命令时:
When executing in the command line as "User X" or as root, I am able to create the new file. However, when I execute the command as:
<?php
exec('sox file1.mp3 file2.mp3 tempfile.mp3 -V3', $output);
foreach($output as $line){
print $line;
}
它不会生成新文件.此外,应返回命令结果的数组为空.
It does not generate the new file. Furthermore, the array that should return the results of of the command is blank.
我用
exec(ls,$output);
我得到了根目录的内容.
and i get the contents of the root directory.
我使用了PHP命令get_current_user()
,它返回了作为网站根目录的目录的所有者.
I used the PHP command get_current_user()
and it returned the owner of the directory that is the root of the web site.
但是,当我使用linux命令whoami
时,我发现它会将当前人员视为"apache".我需要授予apache使用该程序的权利吗?
However, when I use the linux command whoami
I found out that it views the current person as "apache." Would I need to give apache the rights to use the program?
我将继续在线搜索并进行反复试验,以弄清我做错了什么.感谢您的帮助.
I will continue to search online and do trial and error in an effort to figure out what I am doing wrong. Any help is appreciated.
说明
- 我不处于安全模式(我检查了 phpinfo()页面)
- I am not in safe mode (I checked the phpinfo() page")
推荐答案
通常,这是路径问题.您尝试调用的应用程序可能不在Web服务器用户帐户的搜索路径中.我只使用完整路径从PHP调用应用程序.我将该路径存储在设置文件中,以便它可以在所使用的任何系统上使用.
Typically this is a path problem. The application you're trying to call is probably not in the search path of the web server's user account. I only call applications from PHP using the full path. I store that path in settings files so it works across any system it's used on.
这篇关于任何想法,为什么我可以从命令行执行命令,但不能从PHP exec()执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!