You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Laravel Livewire文件上传失败求助(Ubuntu Apache2环境)

解决Laravel Livewire文件上传时缓存目录不存在的问题

1. 确认Apache运行用户及目录权限

Ubuntu环境下Apache默认运行用户为www-data,先验证用户身份:

ps aux | grep apache2

确保Laravel的storage目录及其所有子目录归www-data所有并拥有正确权限:

sudo chown -R www-data:www-data /mypath/to/laravel/storage
sudo chmod -R 755 /mypath/to/laravel/storage

2. 手动生成缓存数据目录

虽然Laravel应自动创建缓存子目录,但可手动补全结构并设置权限:

mkdir -p /mypath/to/laravel/storage/framework/cache/data
sudo chown -R www-data:www-data /mypath/to/laravel/storage/framework/cache/data
sudo chmod -R 755 /mypath/to/laravel/storage/framework/cache/data

3. 检查SELinux限制(若启用)

若服务器开启SELinux,会阻止Apache写入目录,先查看状态:

sestatus

若显示enabled,为storage目录添加正确的SELinux上下文:

sudo chcon -R -t httpd_sys_rw_content_t /mypath/to/laravel/storage

4. 验证缓存驱动配置

检查.env文件,确保使用默认的文件缓存驱动:

CACHE_DRIVER=file

5. 清除缓存并重启服务

执行Laravel缓存清理命令,再重启Apache生效:

php artisan cache:clear
php artisan config:clear
sudo systemctl restart apache2

额外排查点

  • 临时在代码中输出dd(storage_path('app')),确认实际存储路径与配置一致
  • 检查config/livewire.php中的临时上传配置,确保temporary_file_upload的disk和directory设置正常:
'temporary_file_upload' => [
    'disk' => 'local',
    'rules' => 'file|max:12288',
    'directory' => 'livewire-tmp',
    // 其他配置...
],

内容的提问来源于stack exchange,提问作者Khoerul Umam

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.29 08:40:15