在Laravel项目中,我们不时会面临一个破坏性问题:
存储日志文件
production.ERROR: Unable to create lockable file: /var/www/html/storage/framework/cache/data/... Please ensure you have permission to creto create files in this location.
#0 /var/www/html/vendor/laravel/framework/src/Illuminate/Filesystem/LockableFile.php(43)
当问题发生时,ls -l
给出
drwxrwsr-x+ 2 apache apache 4096 Sep 2 14:36 logs
为了解决这个问题,我们运行了sudo chown -R ec2-user:apache logs/
,它提供
drwxrwsr-x+ 2 ec2-user apache 4096 Sep 2 14:36 logs
但这是手动修复..。
因此,我想问:
( A) 如何防止文件系统突然改变所有者,从而破坏编码?
( B)或者,如何在Laravel项目中触发生产错误通知,以便就此类问题发出警告?
发布于 2021-09-02 15:22:34
发布于 2021-09-08 15:04:59
要永久解决这个问题,您必须在代码中给予正确的权限,因此请转到config/logging.php
,您将发现如下所示:
'channels' => [
'stack' => [
'driver' => 'stack',
'channels' => ['daily'],
'ignore_exceptions' => false,
],
'single' => [
'driver' => 'single',
'path' => storage_path('logs/laravel.log'),
'level' => 'debug',
],
'daily' => [
'driver' => 'daily',
'path' => storage_path('logs/laravel.log'),
'level' => 'debug',
'days' => 14,
],
...
],
将'permission' => 0775,
添加到所使用的通道,因此如下所示(我已将其添加到single
和daily
通道中):
'channels' => [
'stack' => [
'driver' => 'stack',
'channels' => ['daily'],
'ignore_exceptions' => false,
],
'single' => [
'driver' => 'single',
'path' => storage_path('logs/laravel.log'),
'level' => 'debug',
'permission' => 0775,
],
'daily' => [
'driver' => 'daily',
'path' => storage_path('logs/laravel.log'),
'level' => 'debug',
'days' => 14,
'permission' => 0775,
],
...
],
这种修复方法在Laravel 6上进行了测试。
https://stackoverflow.com/questions/69032679
复制相似问题