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

casperjs, phantomjs, php, ubuntu, web-scraping

Solution

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

Problem

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?

Original source