1

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!

Avi
  • 728
  • 3
  • 10
  • 20
  • execute `whereis node` or `whereis nodejs` to get the right path – hassan Sep 15 '19 at 10:59
  • Thanks for your reply. I executed both and they both get a blank result. But just to make sure, I ran "node -v" and it got a result. – Avi Sep 15 '19 at 11:24
  • what is the result you get when you execute node -v – hassan Sep 15 '19 at 11:29
  • v10.16.3 This is on an account within a VPS. Should I have installed node in the root rather than in the actual account? – Avi Sep 15 '19 at 11:59
  • 1
    I do not think so , I guess that you need to set the path as following `setNodeBinary('/home/user/path/to/node')` – hassan Sep 15 '19 at 12:10
  • Apparently something was off with the node installation. I reinstalled it and added ->setNodeBinary("/home/user/bin/node") ->setNpmBinary('/home/user/bin/npm') But now I'm getting some other errors. Seems I don't have Chrome installed (and it's refusing to install normally) – Avi Sep 15 '19 at 13:20

0 Answers0