浏览量: 129
1、通过以下命令确认 Web 服务器用户:,确认为 www 用户。系统中有 root 用户和 www 用户(Web 服务器用户)
[root@iZ2zeaj7tnbv8d3gsoy1w5Z wwwroot]# ps aux | grep nginx
root 316309 0.0 0.3 20544 6504 ? Ss Mar08 0:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
www 317674 0.0 1.8 50788 32196 ? S Mar08 0:01 nginx: worker process
www 317675 0.0 1.8 50652 31680 ? S Mar08 0:00 nginx: worker process
root 322874 0.0 0.1 6408 2304 pts/0 S+ 09:56 0:00 grep --color=auto nginx
[root@iZ2zeaj7tnbv8d3gsoy1w5Z wwwroot]#
2、将项目目录的所有者设置为 root 用户:
[root@iZ2zeaj7tnbv8d3gsoy1w5Z wwwroot]# chown -R root:root /home/wwwroot/object
chown: changing ownership of '/home/wwwroot/object/.user.ini': Operation not permitted
[root@iZ2zeaj7tnbv8d3gsoy1w5Z wwwroot]# ls -l
total 0
drwxr-xr-x 2 www www 23 Mar 8 19:17 default
drwxr-xr-x 4 root root 81 Mar 8 17:48 object
[root@iZ2zeaj7tnbv8d3gsoy1w5Z wwwroot]#
3、设置目录权限:755:
[root@iZ2zeaj7tnbv8d3gsoy1w5Z wwwroot]# chmod -R 755 /home/wwwroot/object
chmod: changing permissions of '/home/wwwroot/object/.user.ini': Operation not permitted
[root@iZ2zeaj7tnbv8d3gsoy1w5Z wwwroot]# ls -l
total 0
drwxr-xr-x 2 www www 23 Mar 8 19:17 default
drwxr-xr-x 4 root root 81 Mar 8 17:48 object
[root@iZ2zeaj7tnbv8d3gsoy1w5Z wwwroot]#
4、将运行时目录的所有者设置为 www 用户:
[root@iZ2zeaj7tnbv8d3gsoy1w5Z src]# chown -R www:www backend/runtime
[root@iZ2zeaj7tnbv8d3gsoy1w5Z src]# ls -l
total 700
drwxr-xr-x 12 root root 193 Mar 8 17:48 api
drwxr-xr-x 9 root root 141 Mar 8 17:48 backend
-rwxr-xr-x 1 root root 167 Mar 8 17:48 codeception.yml
drwxr-xr-x 13 root root 190 Mar 8 17:48 common
-rwxr-xr-x 1 root root 2419 Mar 8 17:48 composer.json
-rwxr-xr-x 1 root root 352792 Mar 8 17:48 composer.lock
-rwxr-xr-x 1 root root 293762 Mar 8 17:48 composer.lock.back
drwxr-xr-x 7 root root 86 Mar 8 17:48 console
-rwxr-xr-x 1 root root 864 Mar 8 17:48 docker-compose.yml
drwxr-xr-x 4 root root 46 Mar 8 17:48 environments
drwxr-xr-x 10 root root 160 Mar 8 17:48 frontend
drwxr-xr-x 3 root root 58 Mar 8 17:48 global
-rwxr-xr-x 1 root root 10194 Mar 8 17:48 init
-rwxr-xr-x 1 root root 319 Mar 8 17:48 init.bat
-rwxr-xr-x 1 root root 1524 Mar 8 17:48 LICENSE.md
-rwxr-xr-x 1 root root 1528 Mar 8 20:07 main-local.php
drwxr-xr-x 11 root root 175 Mar 8 17:48 management
-rwxr-xr-x 1 root root 2187 Mar 8 17:48 README.md
-rwxr-xr-x 1 root root 5791 Mar 8 17:48 requirements.php
drwxr-xr-x 5 root root 50 Mar 8 17:48 vagrant
-rwxr-xr-x 1 root root 2914 Mar 8 17:48 Vagrantfile
drwxr-xr-x 50 root root 4096 Mar 8 18:20 vendor
-rwxr-xr-x 1 root root 719 Mar 8 20:08 yii
-rwxr-xr-x 1 root root 323 Mar 8 17:48 yii.bat
[root@iZ2zeaj7tnbv8d3gsoy1w5Z src]# cd backend/
[root@iZ2zeaj7tnbv8d3gsoy1w5Z backend]# ls -l
total 8
drwxr-xr-x 2 root root 26 Mar 8 17:48 assets
-rwxr-xr-x 1 root root 313 Mar 8 17:48 codeception.yml
drwxr-xr-x 2 root root 141 Mar 8 20:08 config
-rwxr-xr-x 1 root root 163 Mar 8 17:48 Dockerfile
drwxr-xr-x 2 root root 22 Mar 8 17:48 models
drwxr-xr-x 2 www www 24 Mar 8 17:48 runtime
drwxr-xr-x 7 root root 152 Mar 8 17:48 tests
drwxr-xr-x 13 root root 207 Mar 8 17:48 views
drwxr-xr-x 4 root root 85 Mar 8 20:08 web
[root@iZ2zeaj7tnbv8d3gsoy1w5Z backend]# cd ..
[root@iZ2zeaj7tnbv8d3gsoy1w5Z src]# sudo chown -R www:www backend/web/assets
[root@iZ2zeaj7tnbv8d3gsoy1w5Z src]# sudo chown -R www:www console/runtime
[root@iZ2zeaj7tnbv8d3gsoy1w5Z src]# sudo chown -R www:www frontend/runtime
[root@iZ2zeaj7tnbv8d3gsoy1w5Z src]# sudo chown -R www:www frontend/web/assets
[root@iZ2zeaj7tnbv8d3gsoy1w5Z src]# sudo chown -R www:www api/runtime
[root@iZ2zeaj7tnbv8d3gsoy1w5Z src]# sudo chown -R www:www api/web/assets
[root@iZ2zeaj7tnbv8d3gsoy1w5Z src]# sudo chown -R www:www management/runtime
[root@iZ2zeaj7tnbv8d3gsoy1w5Z src]# sudo chown -R www:www management/web/assets
[root@iZ2zeaj7tnbv8d3gsoy1w5Z src]#
5、设置 Web 可访问目录权限(确保 frontend/web 和 backend/web 目录允许 Web 服务器用户读取文件。 chmod 755 frontend/web )。设置运行时目录权限(确保 frontend/runtime、backend/runtime、frontend/web/assets 和 backend/web/assets 目录允许 Web 服务器用户读写。chmod -R 775 frontend/runtime)。设置其他目录权限(确保 vendor 和 console 目录允许当前用户读写 sudo chmod -R 755 vendor sudo chmod -R 755 console)。设置环境配置文件权限(environments/ 目录包含环境配置文件,确保其权限安全: sudo chmod -R 755 environments)。这个可以通过执行 ./init 命令完成。
[root@iZ2zeaj7tnbv8d3gsoy1w5Z src]# ./init
Yii Application Initialization Tool v1.0
Which environment do you want the application to be initialized in?
[0] Development
[1] Production
Your choice [0-1, or "q" to quit] 0
Initialize the application under 'Development' environment? [yes|no] yes
Start initialization ...
generate api/config/codeception-local.php
exist api/config/main-local.php
...overwrite? [Yes|No|All|Quit] All
overwrite api/config/main-local.php
unchanged api/config/params-local.php
generate api/config/test-local.php
generate api/web/index-test.php
overwrite api/web/index.php
unchanged api/web/robots.txt
generate backend/config/codeception-local.php
overwrite backend/config/main-local.php
unchanged backend/config/params-local.php
generate backend/config/test-local.php
generate backend/web/index-test.php
overwrite backend/web/index.php
unchanged backend/web/robots.txt
generate common/config/codeception-local.php
overwrite common/config/main-local.php
unchanged common/config/params-local.php
generate common/config/test-local.php
overwrite console/config/main-local.php
unchanged console/config/params-local.php
generate console/config/test-local.php
generate frontend/config/codeception-local.php
overwrite frontend/config/main-local.php
unchanged frontend/config/params-local.php
generate frontend/config/test-local.php
generate frontend/web/index-test.php
overwrite frontend/web/index.php
overwrite frontend/web/robots.txt
generate management/config/codeception-local.php
overwrite management/config/main-local.php
overwrite management/config/params-local.php
generate management/config/test-local.php
generate management/web/index-test.php
overwrite management/web/index.php
overwrite management/web/robots.txt
overwrite yii
generate yii_test
generate yii_test.bat
generate cookie validation key in backend/config/main-local.php
generate cookie validation key in common/config/codeception-local.php
generate cookie validation key in frontend/config/main-local.php
generate cookie validation key in api/config/main-local.php
generate cookie validation key in management/config/main-local.php
chmod 0777 backend/runtime
chmod 0777 backend/web/assets
chmod 0777 console/runtime
chmod 0777 frontend/runtime
chmod 0777 frontend/web/assets
chmod 0777 api/runtime
chmod 0777 api/web/assets
chmod 0777 management/runtime
chmod 0777 management/web/assets
chmod 0755 yii
chmod 0755 yii_test
... initialization completed.
[root@iZ2zeaj7tnbv8d3gsoy1w5Z src]#