Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

muuucho's avatar
Level 11

spatie/laravel-pdf doesn't work on my remote server

I like to get users the posibillity to generate pdf files from blade views so I searched the net and found spaties laravel-pdf. I run composer require spatie/laravel-pdf and npm install puppeteer successfully on my local machine. I have then written code where the user can generate pdf from a blade file and then download the pdf file. This works on my local machine.

I then push it to my remote server, so I first run composer run build and then push everything to my remote server.

When I then try to create a pdf the same way as I did locally, I get a 500 error in and in the log file, it says [2024-11-23 14:08:35] staging.ERROR: Call to undefined function Spatie\Browsershot\escapeshellarg() {"userId":1,"exception":"[object] (Error(code: 0): Call to undefined function Spatie\\Browsershot\\escapeshellarg() at /home/my-account/domains/my-project.se/laravel/vendor/spatie/browsershot/src/Browsershot.php:1144) [stacktrace] Why do I get this error?

0 likes
6 replies
LaryAI's avatar
Level 58

The error you're encountering, Call to undefined function Spatie\Browsershot\escapeshellarg(), suggests that the escapeshellarg() function is not available on your remote server. This function is a built-in PHP function, and its absence usually indicates that the PHP installation on your server is missing the necessary extension or configuration.

Here are some steps you can take to resolve this issue:

  1. Check PHP Version and Extensions: Ensure that your remote server is running a compatible version of PHP and that the necessary extensions are installed. The escapeshellarg() function is part of the standard PHP library, so it should be available if PHP is installed correctly.

    You can check the PHP version and loaded extensions by creating a simple PHP file with the following content and accessing it via your browser:

    <?php
    phpinfo();
    ?>
    

    Look for the disable_functions directive in the output. If escapeshellarg is listed there, it means the function is disabled.

  2. Enable the Function: If escapeshellarg is disabled, you will need to enable it. This can typically be done by editing the php.ini file on your server. Locate the disable_functions directive and remove escapeshellarg from the list. After making changes, restart your web server to apply them.

  3. Verify Server Configuration: Ensure that your server's PHP configuration is not overly restrictive. Some hosting environments disable certain functions for security reasons. If you're on shared hosting, you might need to contact your hosting provider to enable this function.

  4. Alternative Solutions: If you cannot enable escapeshellarg due to hosting restrictions, consider using a different package or approach for generating PDFs that does not rely on this function.

By following these steps, you should be able to resolve the issue and get the spatie/laravel-pdf package working on your remote server. If the problem persists, consider reaching out to your hosting provider for further assistance.

muuucho's avatar
Level 11

Now I have enabled escapeshellarg and I still get a 500 error, now with this message in log file:

mateodioev's avatar

You can try this

pdf()->withBrowsershot(function (Browsershot $browserShot) {
            $browserShot->setNodeBinary('PATH TO NODE');
            $browserShot->setNpmBinary('PATH TO NPM');
            });
1 like
muuucho's avatar
Level 11

@mateodioev Thanks, just installed dompdf. Now it is all working. Thanks for your effort anyway!

Please or to participate in this conversation.