Skip to content

Commit ff10e20

Browse files
committed
Improve steps and description for file permissions.
For readers who already followed the steps before, please run this on your server: ```bash $ su -c 'usermod -g www-data deployer' $ cd /var/www/deployment $ php artisan optimize:clear $ chmod -R 750 . $ chmod -R 770 storage bootstrap/cache ``` Thanks for your support.
1 parent 06ffc03 commit ff10e20

File tree

3 files changed

+18
-23
lines changed

3 files changed

+18
-23
lines changed

src/10. 手动部署 - 生产环境的必要优化.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,21 +52,25 @@ $ composer install --optimize-autoloader --no-dev
5252

5353
## 再谈文件权限
5454

55-
文件权限直接关系到服务器安全与否。通常情况下,我们应当遵循「最小权限原则」,即权限越小越好。对于 Laravel 来说,我个人比较倾向的权限配置为 `750`
55+
文件权限直接关系到服务器安全与否。通常情况下,我们应当遵循「最小权限原则」,即权限越小越好。对于 Laravel 来说,我个人比较倾向的权限配置为:
5656

5757
```bash
58-
$ chmod -R 750 /var/www/deployment
58+
$ cd /var/www/deployment
59+
$ chmod -R 750 .
60+
$ chmod -R 770 storage bootstrap/cache
5961
```
6062

61-
你可以通过在线工具 [Chmod Calculator](https://chmod-calculator.com/) 来解析八进制权限数字
63+
你可以通过在线工具 [Chmod Calculator](https://chmod-calculator.com/) 来计算八进制权限数字
6264

6365
![](https://github.com/wi1dcard/laravel-deployment/raw/master/src/images/f29bb6bf64d66ee9714426882013936b.png)
6466

65-
以上是 `750` 所代表的权限,即文件所有者可 **读、写、执行**,文件所有组可 **读、执行**,其余用户 **均不可**
67+
上图是 `750` 所代表的权限,即文件所有者可 **读、写、执行(进入)**,文件所有组可 **读、执行(进入)**,其余用户 **均不可**
68+
69+
> 注意:对于文件来说,`Execute` 权限表示可执行;对于目录来说,表示可进入(即 `cd`)。为方便描述,以下统称为「执行」权限。
6670
6771
也就是说,运行 Nginx 和 PHP-FPM 的 `www-data` 用户,可读、写、执行;`www-data` 用户组内的用户可读、执行。
6872

69-
更加严格安全的另一个权限推荐是 `640`,不过务必确保 `www-data` 用户具备 `bootstrap/cache``storage` 目录的 **读、写** 权限,在 Laravel 应用运行过程中是需要读写它们的
73+
`770` 则更加宽松 —— 对于 Laravel 运行时需要写入的目录,赋予文件所有组可 **读、写、执行** 权限;也就是说 `www-data` 用户组内的用户可写 `storage``bootstrap/cache` 目录
7074

7175
## 杂项
7276

src/11. 安全加固 - 避免使用根用户.md

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,29 +16,20 @@
1616

1717
## 创建新用户
1818

19-
在创建用户之前,请先新建用户组,例如 `deployment`
19+
请运行以下命令创建新用户
2020

2121
```bash
22-
$ addgroup deployment
22+
$ useradd -m -d /home/deployer -s /bin/bash -g www-data deployer
2323
```
2424

25-
随后创建新用户,例如 `deployer`
26-
27-
```bash
28-
$ useradd -d /home/deployer -s /bin/bash -m deployer
29-
```
30-
31-
其中,`/home/deployer` 为用户家目录(也就是登录到服务器后默认所在的当前目录),`/bin/bash` 为用户的默认 Shell 程序。
32-
33-
接着将用户添加至用户组:
34-
35-
```bash
36-
$ usermod -a -G deployment -G www-data deployer
37-
```
25+
其中:
3826

39-
> 注意:此处使用了两次 -G 参数,将该用户分别添加至 deployment 和 www-data 用户组。
27+
- `-m``-d /home/deployer` 表示用户家目录(也就是登录服务器后默认所在的目录)为 `/home/deployer`,若该目录不存在则创建。
28+
- `/bin/bash` 为用户的默认 Shell 程序。
29+
- `www-data` 为新用户所归属的主用户组。
30+
- `deployer` 为新用户的用户名。
4031

41-
最后,为新用户设置密码:
32+
接着,为新用户设置密码:
4233

4334
```bash
4435
$ passwd deployer

src/13. 更新与回滚.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDpTg16xxOTKZ5XruajPtMhwLE+GFk+Kei1xFPJ65rR
5555
首先,在服务器中执行以下命令,将文件所有者设置为我们手动创建的新用户:
5656

5757
```bash
58-
$ su root -c 'chown -R deployer /var/www/deployment'
58+
$ su -c 'chown -R deployer /var/www/deployment'
5959
```
6060

6161
将远端的 HTTPS 协议地址修改为 SSH 协议地址:

0 commit comments

Comments
 (0)