从PHP运行Linux命令 [英] Running Linux Command from PHP

查看:95
本文介绍了从PHP运行Linux命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个独特的情况.我正在尝试从名为Diascope的PHP脚本运行视频编码程序,该脚本依赖于ImageMagick提供的转换"命令.我有一个bash脚本,它执行一个非常简单的转换,然后运行名为Diascope的应用程序.这是转换代码,以下代码确实起作用,它创建了新文件

I have a bit of a unique situation. I'm trying to run a video encoding program from a PHP script called Diascope, which relies on the 'convert' command provided by ImageMagick. I have a bash script that executes a really simple conversion and then it runs the application called Diascope. This is the conversion code, and the following does work, it creates the new file

convert image.jpg image.png

没有显示任何错误,但随后我像这样运行Diascope

Shows no errors, but then I run Diascope like this

diascope -clean audio.txt

我可以看到Diascope加载了属性,因为它会显示"Diascope 0.2.1":

And I can see that Diascope loads property because it prints "Diascope 0.2.1":

直径0.2.1(毫秒2006-2010)幻灯片生成器请参阅 http://diascope.sf.net 以获得文档和更新.

diascope 0.2.1 (ms 2006-2010) slideshow generator See http://diascope.sf.net for documentation and updates.

错误:找不到可执行程序:转换请参阅 发行说明中对diascope的要求.

Error: executable program not found: convert Please see the requirements for diascope in the release notes.

当我运行shell_exec("whoami");时,它会显示"nobody"

When I run shell_exec("whoami"); it prints "nobody"

那么为什么我可以自己运行转换,但是透视"过程似乎无法利用它?我曾尝试进入/usr/local/bin/convert并将其更改为777,但似乎没有任何效果,我还能在这里尝试什么?

So why can I run convert by itself, but the "diascope" process can't seem to utilize it? I have tried going into /usr/local/bin/convert and chmoding it to 777, but it didn't seem to have any effect, what else could I try here?

更新:我可能应该补充一点,当我尝试在终端上以root身份运行diascope -clean audio.txt时,它会像应有的那样创建audio.flv文件,而且我似乎也看不到sudo su nobody,它会返回This account is currently not available.

UPDATE: I should probably add that when I try to run diascope -clean audio.txt as root on the terminal, it creates the audio.flv file like it should, also I can't seem to sudo su nobody it returns This account is currently not available.

推荐答案

PHP以与apache相同的用户身份运行,该用户通常是www-data或没有用户.我相信您可以使用suPHP + apache更改运行PHP的用户.

PHP runs as the same user as apache, which is typically www-data or nobody. I believe you can use suPHP+apache to change the user that PHP runs under.

这篇关于从PHP运行Linux命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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