使用exec()从PHP运行PhantomJS [英] Running PhantomJS from PHP with exec()
问题描述
我有以下脚本:
#!/bin/sh
export DISPLAY=:0
phantomjs --version
它尝试通过以下PHP脚本运行它:
It try to run it from the following PHP script:
<?php
$result = shell_exec('sh test.sh');
echo $result;
?>
此脚本返回以下错误:
[Thu Jun 19 10:31:31 2014] [error] [client] test.sh: line 3: phantomjs: command not found
我尝试在控制台中手动运行phantomjs -v
,并且运行正常.我检查了PATH
,并正确定义并找到了phantomjs.
I tried to run phantomjs -v
by hand in a console, and it runs fine. I checked the PATH
, and phantomjs is correctly defined and found.
执行环境是具有LiveConfig的虚拟服务器. 有人可以帮助我了解我在做什么错吗?
The execution environment is a virtual Server with LiveConfig. Can someone help me understand what I'm doing wrong ?
推荐答案
您的PATH
可能缺少phantomjs可执行文件的位置. PhantomJS可能已安装在/usr/local/bin
中,因此您需要将其添加到PATH
变量中:
Your PATH
probably lacks the location for the phantomjs executable. PhantomJS is probably installed in /usr/local/bin
so you need to add this to your PATH
variable:
#!/bin/sh
export DISPLAY=:0
PATH=$PATH:/usr/local/bin
phantomjs --version
要检查当前的PATH
是什么,可以使用以下命令开始shell脚本:
To check what the current PATH
is, you could begin the shell script with:
#!/bin/sh
echo $PATH
这篇关于使用exec()从PHP运行PhantomJS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!