Using PHP's exec() gives error: Fatal: [Errno 2] No such file or directory; did you install

有些话、适合烂在心里 提交于 2019-12-10 17:54:15

问题


I'm trying to use PHP to exec() a binary casperjs,

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

but I am getting the error

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

CasperJS runs on top of PhantomJS, both which I manually installed and created a link at /usr/local/bin/phantomjs and /usr/local/bin/casperjs. So I am guessing casperjs calls phantomjs when it runs.

However it works fine when I ssh into the server and run

casperjs /var/www/mysite/application/phantomjs/test.js

What went wrong? I think casperjs cannot run phantomjs as a web user? If this is true, how can it be fixed?


回答1:


Just try to call the exec command with the full path of the program. For example

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

Also make sure that you are allowed to execute that program via the web server, especially if you use the php safe_mode on. Have a look at safe_mode_exec_dir




回答2:


I had exactly the same problem and found a working solution here: https://groups.google.com/forum/?fromgroups=#!topic/casperjs/92yUM9O0XjA



来源:https://stackoverflow.com/questions/14130311/using-phps-exec-gives-error-fatal-errno-2-no-such-file-or-directory-did

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!