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

Laravel文件缓存:能否配置权限掩码使新缓存文件以664权限创建?

Adjusting Laravel Cache File Permissions to 664

Got it, let's fix this permission issue you're facing with Laravel's cache files. You absolutely can configure the framework to generate new cache files with a 664 permission mask instead of the default 644—here's how to do it properly:

Step 1: Update Your Cache Configuration

Open your config/cache.php file, find the file driver section (since you're using file-based caching), and add a new permission key set to 0664.

Your modified configuration block should look like this:

'file' => [
    'driver' => 'file',
    'path' => storage_path('framework/cache/data'),
    'permission' => 0664, // Add this line to set the desired permission mask
],

Important: Don't skip the leading 0 before 664—this tells PHP to treat the number as an octal value, which is required for correct permission handling. Omitting it will result in wrong permissions being applied.

Step 2: Fix Existing Cache Files

The new permission setting only affects newly created cache files. To fix the existing 644 permission files that your shell user can't delete, run this command in your project root:

chmod -R g+w storage/framework/cache/data

This grants write access to the www-data group (which your shell user belongs to) for all existing cache files and directories.

A Quick Breakdown of 664 Permissions

This permission mask gives exactly what you need:

  • Owner (typically the web server's www-data user): Read and write access
  • Group (your shell user is part of this): Read and write access
  • Others: Read-only access

This setup lets both the web server process and your shell user manage cache files without permission conflicts.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.01 01:22:42