使用PHP的exec()给出错误:致命:[Errno 2]没有这样的文件或目录;你安装了吗?

时间:2013-01-02 22:32:37

标签: php ubuntu web-scraping phantomjs casperjs

我正在尝试使用PHP exec()二进制casperjs

exec('casperjs /var/www/mysite/application/phantomjs/test.js');

但我收到了错误

Fatal: [Errno 2] No such file or directory; did you install phantomjs?

CasperJS在PhantomJS之上运行,我手动安装并在/usr/local/bin/phantomjs/usr/local/bin/casperjs创建了一个链接。所以我猜猜casperjs在运行时会调用phantomjs。

然而,当我进入服务器并运行

时,它工作正常
casperjs /var/www/mysite/application/phantomjs/test.js

出了什么问题?我认为casperjs无法作为网络用户运行phantomjs?如果这是真的,怎么解决?

2 个答案:

答案 0 :(得分:4)

我遇到了完全相同的问题,并在此处找到了有效的解决方案:https://groups.google.com/forum/?fromgroups=#!topic/casperjs/92yUM9O0XjA

答案 1 :(得分:1)

尝试使用程序的完整路径调用exec命令。例如

exec('/usr/local/bin/casperjs /var/www/mysite/application/phantomjs/test.js');

还要确保允许您通过Web服务器执行该程序,尤其是在使用php safe_mode on时。看看safe_mode_exec_dir