Laravel 5.7 无法加载 `storage/framework/cache/data` 并写入 `./storage/logs/laravel-2019-06-11.log`
Laravel 5.7 unable to load `storage/framework/cache/data` and write into `./storage/logs/laravel-2019-06-11.log`
我在 laravel 5.7 安装下有一个项目,由于某种原因我收到以下错误:
file_put_contents(/home/vagrant/code/storage/framework/cache/data/1c/6e/1c6ea8378a1030f85a05f4cb2262de1e2164efa6): failed to open stream: No such file or directory
为了减轻错误,我尝试了以下操作:
- 基于权限的尝试:
chmod 777 -R storage
chmod 0777 -R storage
- 基于艺术家的尝试:
php artisan cache:clear
php artisan config:clear
php artisan config:cache
php artisan view:clear
- php-fpm默认用户设置:
sudo chown -R $USER:www-data storage
sudo chown -R $USER:www-data bootstrap/cache
另外,为了开发,我将 vagrant 与位于项目根目录的 Vagrantfile
一起使用:
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/xenial64"
config.vm.box_version = "20180917.0.0"
config.vm.box_download_insecure = true
config.vm.provider "virtualbox" do |vb|
vb.name = "myapp-api"
vb.memory = 2024
vb.cpus = 1
vb.customize [ "modifyvm", :id, "--uartmode1", "disconnected" ]
end
config.vm.network "private_network", ip: "192.168.10.111"
config.vm.network "forwarded_port", guest: 80, host: 8888
config.vm.network "forwarded_port", guest: 22, host: 2223
config.vm.synced_folder "./.", "/home/vagrant/code"
# Provision Scripts
end
但是这些都未能解决问题。
编辑 1
文件夹 framework/cache/data
已经存在 ls -l
显示:
$ ls -l /home/vagrant/code/storage/framework/cache/ | grep data
drwxrwxr-x 1 vagrant vagrant 4096 Jun 11 10:46 data
通过做:
rm -rf storage/framework/cache
mkdir -p storage/framework/cache
导致以下 新 错误:
The stream or file "/home/vagrant/code/storage/logs/laravel-2019-06-11.log" could not be opened: failed to open stream: Permission denied
所以在我的调查中显示:
$ ls -l /home/vagrant/code/storage/logs
total 112
drwxrw-rw- 1 vagrant vagrant 4096 Jun 10 17:31 .
drwxr-xr-x 1 vagrant vagrant 4096 Jun 10 15:47 ..
-rwxrwxrwx 1 vagrant vagrant 14 Jun 10 15:47 .gitignore
-rwxrwxrwx 1 vagrant vagrant 96507 Jun 10 18:09 laravel-2019-06-10.log
这意味着它不仅具有足够的写入权限。我还 运行 以下命令:
$ ls -l /home/vagrant/code/storage/ | grep logs
drwxrw-rw- 1 vagrant vagrant 4096 Jun 10 17:31 logs
意味着仍然有良好的授权权限以便 laravel 写入文件。仍然错误显示相反。
此外我试过这个:
mv bootstrap/cache/config.php ~/
我还尝试了以下方法:
rm -rf storage/logs/*
./artisan cache:clear
问题依旧。
确保此路径存在:
/home/vagrant/code/storage/framework/cache/data
根据您显示的内容 /home/vagrant/code/storage/framework/cache/data
没有项目名称,/home/vagrant/code/<name-of-your-project>/storage/framework/cache/data
检查您的 config/cache.php
是否对应于:
'file' => [
'driver' => 'file',
'path' => storage_path('framework/cache/data'),
],
您可以尝试转储 storage_path()
以查看路径是什么样的
问题是代码是 运行 作为 www-data
用户。要修复此问题,您应该使用名为 vagrant
.
的用户和组创建自定义 php-fpm
池
通过这个配置实现php-fpm
配置:
[www-vagrant]
listen = 127.0.0.1:9001;
user=vagrant
group=vagrant
并使用 tcp://127.0.0.1:9001
进入 nginx 配置。或者,您可以使用默认 (www
) 池,以防所有 php 脚本都使用单个用户执行:
[www]
# Existing pieces of configuration
user=vagrant
group=vagrant
更多信息位于此处:https://serversforhackers.com/c/php-fpm-multiple-resource-pools(请记住,对于以后的 php 版本,将路径的 /etc/php5
部分替换为 /etc/php^Version^
,其中 ^Version^
是 php.
的所需版本
如果你使用的是Docker,首先在项目目录下进入终端,然后运行下面的命令
docker-compose执行php/bin/sh
然后运行下面的命令
chown -R www-data: www-data ./
然后,如果没有结果,从bootstrap /缓存部分删除一次配置文件,然后运行以下命令:
php artisan 配置:缓存
希望问题得到解决。
我在 laravel 5.7 安装下有一个项目,由于某种原因我收到以下错误:
file_put_contents(/home/vagrant/code/storage/framework/cache/data/1c/6e/1c6ea8378a1030f85a05f4cb2262de1e2164efa6): failed to open stream: No such file or directory
为了减轻错误,我尝试了以下操作:
- 基于权限的尝试:
chmod 777 -R storage
chmod 0777 -R storage
- 基于艺术家的尝试:
php artisan cache:clear
php artisan config:clear
php artisan config:cache
php artisan view:clear
- php-fpm默认用户设置:
sudo chown -R $USER:www-data storage
sudo chown -R $USER:www-data bootstrap/cache
另外,为了开发,我将 vagrant 与位于项目根目录的 Vagrantfile
一起使用:
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/xenial64"
config.vm.box_version = "20180917.0.0"
config.vm.box_download_insecure = true
config.vm.provider "virtualbox" do |vb|
vb.name = "myapp-api"
vb.memory = 2024
vb.cpus = 1
vb.customize [ "modifyvm", :id, "--uartmode1", "disconnected" ]
end
config.vm.network "private_network", ip: "192.168.10.111"
config.vm.network "forwarded_port", guest: 80, host: 8888
config.vm.network "forwarded_port", guest: 22, host: 2223
config.vm.synced_folder "./.", "/home/vagrant/code"
# Provision Scripts
end
但是这些都未能解决问题。
编辑 1
文件夹 framework/cache/data
已经存在 ls -l
显示:
$ ls -l /home/vagrant/code/storage/framework/cache/ | grep data
drwxrwxr-x 1 vagrant vagrant 4096 Jun 11 10:46 data
通过做:
rm -rf storage/framework/cache
mkdir -p storage/framework/cache
导致以下 新 错误:
The stream or file "/home/vagrant/code/storage/logs/laravel-2019-06-11.log" could not be opened: failed to open stream: Permission denied
所以在我的调查中显示:
$ ls -l /home/vagrant/code/storage/logs
total 112
drwxrw-rw- 1 vagrant vagrant 4096 Jun 10 17:31 .
drwxr-xr-x 1 vagrant vagrant 4096 Jun 10 15:47 ..
-rwxrwxrwx 1 vagrant vagrant 14 Jun 10 15:47 .gitignore
-rwxrwxrwx 1 vagrant vagrant 96507 Jun 10 18:09 laravel-2019-06-10.log
这意味着它不仅具有足够的写入权限。我还 运行 以下命令:
$ ls -l /home/vagrant/code/storage/ | grep logs
drwxrw-rw- 1 vagrant vagrant 4096 Jun 10 17:31 logs
意味着仍然有良好的授权权限以便 laravel 写入文件。仍然错误显示相反。
此外我试过这个:
mv bootstrap/cache/config.php ~/
我还尝试了以下方法:
rm -rf storage/logs/*
./artisan cache:clear
问题依旧。
确保此路径存在:
/home/vagrant/code/storage/framework/cache/data
根据您显示的内容 /home/vagrant/code/storage/framework/cache/data
没有项目名称,/home/vagrant/code/<name-of-your-project>/storage/framework/cache/data
检查您的 config/cache.php
是否对应于:
'file' => [
'driver' => 'file',
'path' => storage_path('framework/cache/data'),
],
您可以尝试转储 storage_path()
以查看路径是什么样的
问题是代码是 运行 作为 www-data
用户。要修复此问题,您应该使用名为 vagrant
.
php-fpm
池
通过这个配置实现php-fpm
配置:
[www-vagrant]
listen = 127.0.0.1:9001;
user=vagrant
group=vagrant
并使用 tcp://127.0.0.1:9001
进入 nginx 配置。或者,您可以使用默认 (www
) 池,以防所有 php 脚本都使用单个用户执行:
[www]
# Existing pieces of configuration
user=vagrant
group=vagrant
更多信息位于此处:https://serversforhackers.com/c/php-fpm-multiple-resource-pools(请记住,对于以后的 php 版本,将路径的 /etc/php5
部分替换为 /etc/php^Version^
,其中 ^Version^
是 php.
如果你使用的是Docker,首先在项目目录下进入终端,然后运行下面的命令 docker-compose执行php/bin/sh 然后运行下面的命令 chown -R www-data: www-data ./ 然后,如果没有结果,从bootstrap /缓存部分删除一次配置文件,然后运行以下命令: php artisan 配置:缓存 希望问题得到解决。