Running Linux Command from PHP

2019-02-26 00:44发布

问题:

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

Shows no errors, but then I run Diascope like this

diascope -clean audio.txt

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

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

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

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

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?

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.

回答1:

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.