I'm using Browsershot on a laravel project. When I use in on localhost it works perfectly. However, no matter what I do, I can't seem to get it to work on the live server. I'm running it on a Linux VPS.
Here is my code (within a controller):
use Illuminate\Http\Request;
use Spatie\Browsershot\Browsershot;
use Spatie\Image\Manipulations;
class screenshotController extends Controller
{
public function take($url){
$directory = "screenshots/" . date('m') . "/";
$id = uniqid(). ".jpeg";
if (!file_exists($directory)) {
mkdir($directory, 0777, true);
}
Browsershot::url("http://".$url)
->windowSize(1920, 1080)
->fit(Manipulations::FIT_CONTAIN, 525, 394)
->noSandbox()
->ignoreHttpsErrors()
->save($directory.$id);
return $directory.$id;
}
}
I've tried adding ->setNodeModulePath("/public_html/node_modules/")
as well.
This is the error I'm getting:
(1/1) ProcessFailedException
The command "PATH=$PATH:/usr/local/bin NODE_PATH='/public_html/node_modules/' node
'/home/XXXX/public_html/vendor/spatie/browsershot/src/../bin/browser.js'
'{"url":"http:\/\/xxxxxxx.net","action":"screenshot","options":
{"type":"png","path":"screenshots\/09\/5d7e151bf330c.jpeg","args":["--no-sandbox"],"viewport":
{"width":1920,"height":1080},"ignoreHttpsErrors":true}}'" failed.
Exit Code: 127(Command not found)
Working directory: /home/XXXXX/public_html/public
Output:
================
Error Output:
================
sh: node: command not found
I'm assuming it has something to do with the npm location or node_modules location.
I saw this section in the manual :
Browsershot::html('Foo')
->setNodeBinary('/usr/local/bin/node')
->setNpmBinary('/usr/local/bin/npm');
But I really don't understand how to use it in my situation.
Any help would be hugely appreciated.
Thank you!