phplaravelopen-basedirknp-snappy

How to fix open_basedir restriction error in shared server?


I'm setting up laravel-snappy to create pdf.

My snappy config is as below

<?php
return array(
'pdf' => array(
        'enabled' => true,
        'binary' => base_path('vendor/h4cc/wkhtmltopdf/bin/wkhtmltopdf'),
...

By running config('snappy') inside tinker, I also get the exact required path that is within the laravel project folder

But I'm getting the following error

local.ERROR: is_dir(): open_basedir restriction in effect. File(/tmp) is not within the allowed path(s):

How can I solve this without changing the php settings?


Solution

  • It seems like the package tries to write to the /tmp folder but is restricted through PHPs ini option open_basedir.

    You can change this folder path to something within your application, maybe storage/tmp, with the setTemporaryFolder() method.

    $pdf = App::make('snappy.pdf.wrapper');
    $pdf->setTemporaryFolder(storage_path('tmp'));
    // ...