phantommagick
phantommagick copied to clipboard
shell_exec("wich phantomjs") returns null
I'm using laravel 5.1 and I have downloaded phantomjs and copied it into public folder.
I also copied that file into /usr/bin and make both of them executable by running chmod +x on my mac.
But still shell_exec() function in Runner.php line 137 returns null and I get Binary does not exist error.
What should I do to make it work? Am I doing something wrong? Any help would be appreciated.
Hi @parsipixel, Follow the following steps:
Step1: Download the Mac version of Phantonjs binary. https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.0.0-macosx.zip
Step2: Create a folder called bin inside your root project directory and place the phantomjs binary inside the bin directory.
Laravel5.1/bin/phantomjs
Step3: find the full physical path of the phantomjs binary. if you follow upper steps:
$path = base_path() . '/bin/phantomjs';
Step4: Set the binary path.
$path = base_path() . '/bin/phantomjs';
$conv->setBinary($path);
$conv->source('http://google.com')
->toPng()
->download('google.png');
Hi @anam-hossain , Thank you for the answer.
It's still returning null and I get the same Binary does not exist error.
It tried
shell_exec('echo $0')
it returned sh
but echo $0 in terminal returns -bash
Could it be the problem?
I ran into this as well.
Even through I was setting the exact path with setBinary it was failing. In the end, just before I did $converter = new Converter();
I did
putenv($x = 'PATH='.$_ENV["PATH"] . ':/usr/local/bin');
which now caused it to work.
Even if my phantomjs was in base_path()/bin/ the which command would fail until I had set my PATH (even if phantomjs wasn't in that path). I am sure there is a deeper reason to it... but, that seemed to solve it.
If might be useful if in the verifyBinary function we check to see if a full path to the executable has been set, and if so verify file exists and it is executable. That way if the binary is out of the PATH it will still easily work.
If anybody still has shell_exec() problem with returning null, especially on NGINX (Linux). I've posted an issue with resolution HERE
the same problem happend in my web (php-fpm + nginx) i dont want to edit this source code , i rewrite verifyBinary() in my Controller ,and my controller extends Converter