简体   繁体   中英

ZipArchive::close(): Failure to create temporary file in AWS EC2 Linux

I am working on cron jobs in laravel 5.2, when i try to call a controller function from schedule to create excel sheet getting Error. but runs fine in postman.

ZipArchive::close(): Failure to create temporary: No such file or directory' in /var/www/html/Expenses/vendor/phpoffice/phpexcel/Classes/PHPExcel/Writer/Excel2007.php:398

Problem with temp file permission for zipArchive?

I am getting above error while save phpexcel sheet to directory(777).

$excel_path = 'SubmittedSheets/'.$userId.'-'.uniqid().'.xlsx';
$objWriter->save($excel_path);

Need Absolute path to save excel file in AWS Ec2 Linux for PHPExcel.

$excel_path = '/var/www/html/MyProject/public/SubmittedSheets/'.$userId.'-'.uniqid().'.xlsx';
$objWriter->save($excel_path); 

I solved it on my Mac OS system by simply uncommenting the line

;sys_temp_dir = "/tmp"

in php.ini , ie changing it to

sys_temp_dir = "/tmp"

Directory where the temporary files should be placed. Defaults to the system default (see sys_get_temp_dir)

Not sure which directory it tried to use as default though, possibly /var/tmp , which my Homebrew PHP installation doesn't seem to have permission to write to.

I've tried a lot of things and spend a lot of time. Solution for Ubuntu + Vesta + Nginx + Apache was in file:

:/home/admin/conf/web/your-domain.com.apache2.ssl.conf

set up tmp folder like in my example:

<Directory /home/admin/web/your-domain.com/public_html>
    AllowOverride All
    SSLRequireSSL
    Options +Includes -Indexes +ExecCGI
    php_admin_value open_basedir 
    /home/admin/web/your-domain.com/public_html:/tmp
    php_admin_value upload_tmp_dir /tmp
    php_admin_value session.save_path /tmp
</Directory>

example image

don't forget to restart the apache service

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM