# Laravel 部署：文件夹权限

问 `Laravel` 部署后，哪些文件夹需要写权限？

答 `storage` 目录包含编译后的 `Blade` 模板、`session` 会话生成的文件、缓存文件以及框架生成的其他文件。\
\
这个目录被细分成 `app` 、 `framework` 和 `logs` 三个子目录：

`app` 目录可以用来存储应用生成的任何文件；\
&#x20;`framework` 目录用来存储框架生成的文件和缓存； \
`logs` 目录包含应用的日志文件。 \
\
如果 `storage` 目录的权限不正确，可能导致应用运行出现异常，例如出现：

`The stream or file "/var/www/storage/logs/laravel.log" could not be opened: failed to open stream: Permission denied`

所以 `storage` 需要读写权限，设置如下：<br>

方法一 更改 `storage` 文件夹权限 `chmod -R 0755 storage` \
\
更改 `storage` 文件夹拥有者与 `php-fpm.conf` 运行用户一致，如 `php-fpm.conf` 配置为

```php
; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
;       will be used.
user = www-data
group = www-data
```

则命令为  `chown -R www-data:www-data storage`\
\
方法二更改 `storage` 文件夹权限为 `chmod -R 0777 storage`\
\
注意

生产服务器上应该遵循「最小权限原则」，推荐使用「方法一」


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://xn--6o0a585a.gitbook.io/devops/fu-wu/laravel-bu-shu/laravel-bu-shu-wen-jian-jia-quan-xian.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
