Timothy
Timothy

Reputation: 77

Browsershot in Laravel not Saving PDF on Linux Server (Working on Windows)

I am using the Browsershot package in a Laravel application to generate and save PDFs. The process works perfectly on my local Windows machine, but when I try to run the same application on my Linux-based shared server, the PDF is not being saved, and I am receiving the following error:

Spatie\Browsershot\Exceptions\CouldNotTakeBrowsershot
For some reason Chrome did not write a file at `/home/mhtechno/public_html/boyscout/Heart_of_Virginia_timeline.pdf`. Command ======= [] Output ======

   $fileName = "{$sanitizedCouncilName}_timeline.pdf";
        $filePath = ("/home/mhtechno/public_html/boyscout/{$fileName}");
       
    $pdf = Browsershot::html($pdfHtml)
        ->noSandbox()
        ->setOption('executablePath', '/home/mhtechno/.cache/puppeteer/chrome/linux-130.0.6723.116/chrome-linux64/chrome')
        ->addChromiumArguments(['no-sandbox', 'disable-setuid-sandbox'])
        ->setOption('printBackground', true)
        ->setOption('no-stop-slow-script', false)
        ->setOption('disable-execute-javascript', false)
        ->setOption('height', '2000mm')
        ->setOption('headless', true)
        ->setOption('width', '800mm')
        ->setOption('dumpio', true)
        ->useTemporaryDirectory('/tmp')
        ->timeout(120) 
        ->save($filePath);

What I've Tried So Far:

Permissions Check:

I confirmed that the target directory (/home/mhtechno/public_html/boyscout/) has write permissions. Running ls -ld /home/mhtechno/public_html/boyscout/ shows that the directory permissions are set to drwxrwxr-x, and the ownership is mhtechno mhtechno.

Browsershot Configuration:

The HTML is rendered correctly and passed to Browsershot for PDF generation. I use the setOption('executablePath', '/home/mhtechno/.cache/puppeteer/chrome/linux-130.0.6723.116/chrome-linux64/chrome') option to specify the path to Chrome. Testing with Other Directories:

I attempted to change the file path to /tmp/, which is a temporary directory and should have sufficient permissions. However, it still doesn't work. No Sudo Access:

I am on a shared hosting environment and do not have root or sudo access, so I cannot modify the system-wide configurations or install packages like libnss3 or other dependencies. phpinfo() Check:

I confirmed that my web server user is mhtechno, as shown in the phpinfo() page.

#My Questions:# What could be causing Browsershot to fail to save the file on a Linux server when it works on Windows? Are there any server-side configurations or permissions I need to adjust, given that I don't have sudo access? Is there a specific environment setting or dependency I might be missing on the Linux server? Are there any known issues with running Browsershot on shared hosting environments? I would appreciate any help or suggestions on how to resolve this issue.

Thank you!

Upvotes: 0

Views: 105

Answers (0)

Related Questions