问题
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