ZipArchive::close(): 无法在 AWS EC2 中创建临时文件 Linux

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

我正在 laravel 5.2 中处理 cron 作业,当我尝试从计划调用控制器函数以创建 excel sheet 时出现错误。但在邮递员中运行良好。

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

zipArchive 的临时文件权限有问题?

将 phpexcel sheet 保存到目录 (777) 时出现上述错误。

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

需要绝对路径才能在 AWS Ec2 Linux 中为 PHPExcel 保存 excel 文件。

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

我尝试了很多东西,也花了很多时间。 Ubuntu + Vesta + Nginx + Apache 的解决方案在文件中:

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

像我的示例一样设置 tmp 文件夹:

<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

别忘了重启apache服务

我在 Mac OS 系统上解决了这个问题,只需取消注释行

;sys_temp_dir = "/tmp"

php.ini中,即将其更改为

sys_temp_dir = "/tmp"

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

不确定它尝试使用哪个目录作为默认目录,可能 /var/tmp,我的 Homebrew PHP 安装似乎没有写入权限。