我在编辑位于
storage/framework/cache
的 Laravel 缓存时遇到了困难。我正在运行一个保存到某个缓存的作业,但是每次运行该作业时,都会发生此错误:
ERROR: file_put_contents(/var/www/html/---/storage/framework/cache/data/3c/c7/3cc7fd54b5a3cb08ceb0754f58371cec1196159a): failed to open stream: Permission denied
详情
sudo chown -R www-data:www-data storage
,以及 sudo chmod -R 775 /home/<user>/<laravel folder>/storage
ls -lh /storage/framework/cache
返回以下内容:drwsrwsr-x 55 www-data www-data 4.0K Jan 18 20:56 data
。如有任何帮助,我们将不胜感激!预先感谢您。
我使用
sudo php artisan cache:clear
完全清除了缓存。后来就再也没有出现过这个问题。
反对 Ismoil 的答案:永远不要创建 Laravel 存储文件夹
777
。这会带来安全风险。
1) 如果您查看
cache.php
配置文件,您会发现对于文件驱动程序,storage/framework/cache/data
文件夹已设置为写入:
'file' => [
'driver' => 'file',
'path' => storage_path('framework/cache/data'),
],
这意味着必须正确设置该文件夹的权限,以便 Web 服务器用户可以成功写入该文件夹。
2)或者你可以为我运行这个命令它解决了我的问题
php artisan cache:clear
chmod -R 775 storage/
composer dump-autoload
其实只是需要
php artisan cache:clear
但这只是暂时的,当用新的IP或其他东西登录帐户时。仍然发出来了。
所以尝试 chmod:
chmod -R 775 storage
和
chmod -R 775 storage/*
解决问题
我使用 sudo php artisan optimize:clear 完全清除了优化。后来就再也没有出现过这个问题。
如果您使用 redis 那么您应该设置 .env 变量
CACHE_DRIVER=redis