知道为什么我可以从命令行执行命令但不能从 PHP exec() 执行命令
好吧,
我做了一些创造性的搜索,但遇到了障碍。
我正在尝试使用Linux 程序“sox”。我试图从我的 PHP 脚本中调用它。如果我使用命令行,该脚本确实有效。但是,当我使用 PHP exec 时,它不起作用。
示例:(
sox file1.mp3 file2.mp3 tempfile.mp3 -V3
“V3”指定详细输出)
当以“用户 X”或 root 身份在命令行中执行时,我能够创建新文件。但是,当我执行命令时:
<?php
exec('sox file1.mp3 file2.mp3 tempfile.mp3 -V3', $output);
foreach($output as $line){
print $line;
}
它不会生成新文件。此外,应返回命令结果的数组为空。
我已经完成了一个简单的文本
exec(ls,$output);
,并且获得了根目录的内容。
我使用了 PHP 命令 get_current_user()
,它返回了网站根目录的所有者。
但是,当我使用 linux 命令 whoami
时,我发现它将当前人视为“apache”。我需要给apache使用该程序的权利吗?
我将继续在网上搜索并进行尝试和错误,以找出我做错了什么。任何帮助表示赞赏。
说明
- 我未处于安全模式(我检查了 phpinfo() 页面”)
OK,
I have done some creative searches and am kind of hitting a road block.
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.
Example:
sox file1.mp3 file2.mp3 tempfile.mp3 -V3
("V3" specifies a verbose output)
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.
I have done a simple text with
exec(ls,$output);
and i get the contents of the root directory.
I used the PHP command get_current_user()
and it returned the owner of the directory that is the root of the web site.
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.
Clarifications
- I am not in safe mode (I checked the
phpinfo() page")
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
通常这是一个路径问题。您尝试调用的应用程序可能不在 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 以运行 apache 的用户身份运行,而这通常是无人(没有创建目录权限的用户)。尝试在每个人都可以写入的地方创建输出并检查运行 apache 的用户。
I am sure php runs as the user running your apache, and this is most often nobody (a user without rights to create directories). Try to create your output somewhere where everyone is allowed to write and check the user apache runs under.
检查您当前是否在 safe_mode 下运行 PHP
Check if you are currently running PHP in safe_mode