7

I'm getting this error in my laravel application. Mpdf \ MpdfException (E_ERROR) Temporary files directory "/var/www/html/../temp/" is not writable

Please anybody tell me the solution to fix this issue.

jawahar j
  • 183
  • 2
  • 5
  • 13
  • Have you checked the permissions for that particular directory? I'm guessing that the directory needs write permissions for the HTTP server user (which in most cases is `apache` or `www-data` depending on the Linux distribution). – Bogdan Mar 05 '19 at 16:40
  • I'm using centOS . So here how can i give the permission – jawahar j Mar 05 '19 at 16:43
  • Did you try setting temprory folder path in config `'tempDir' => __DIR__ . '/../../tmp',` – Vipertecpro Mar 05 '19 at 16:53
  • Additionally, did you provide permission to write `chmod 777 /var/www/protected/vendor/mpdf/mpdf/tmp` – Vipertecpro Mar 05 '19 at 16:55
  • Yes path also given, and this working perfectly in local. But in server only not working. – jawahar j Mar 06 '19 at 00:49

4 Answers4

6

I fixed it like so:

$mpdf = New \Mpdf\Mpdf(['tempDir'=>storage_path('tempdir')]);

storage_path('tempdir') is the laravel-managed temporary directory.

user151841
  • 17,377
  • 29
  • 109
  • 171
4

I solved my issue by specifying tempDir to a usable temp directory

In config/pdf.php

<?php
return [
    'mode'                  => 'utf-8',
    'format'                => 'A4',
    'author'                => '',
    'subject'               => '',
    'keywords'              => '',
    'creator'               => 'Laravel Pdf',
    'display_mode'          => 'fullpage',
    'tempDir'               => base_path('storage/app/mpdf'),
    'pdf_a'                 => false,
    'pdf_a_auto'            => false,
    'icc_profile_path'      => ''
];

if you are not found config/pdf.php then you should publish package's config file to your config directory by using following command:

php artisan vendor:publish
Prakash Sah
  • 41
  • 1
  • 3
0

If you are using docker, and having trouble to give the permissions make sure to enter in the docker container with root user using the follow command:

docker container exec -u 0 -it yourContainer bash

From this answer: Root password inside a Docker container

Laércio Lopes
  • 132
  • 2
  • 9
-1
  1. go to the directory "/var/www/html/../temp/" and check if it exists.
  2. if it does not exists then create it.
  3. if it exists give the necessary permission to it (usually 777 depends on your environment)
  • without giving permission as `777` is there any other way? `777` is bit risky i guess. – Rakibul Haq May 10 '19 at 20:28
  • it's a temporary folder .. you can choose to give only write write access without reading but whats the point! you need your script to read and write data in this folder – Ibrahim Bakhsh Jul 24 '19 at 21:11