A advanced template for Yii2, the process of setting directory permissions
1. Confirm the Web server user with the following command: , confirm as the WWW user. There are root users and WWW users in the system (web server users)
[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. Set the owner of the project directory to root user:
[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. Set directory permissions: 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. Set the owner of the runtime directory to the WWW user:
[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. Set the web access directory permissions (make sure that the frontend/web and backend/web directories allow web server users to read files. chmod 755 frontend/web ). Set runtime directory permissions (make sure that the Frontend/Runtime, Backend/Runtime, Frontend/Web/Assets and Backend/Web/Assets directory allow web server users to read and write. chmod -R 775 frontend/runtime). Set other directory permissions (make sure that the vendor and console directories allow the current user to read and write sudo chmod -r 755 vendor sudo chmod -r 755 console). Set environment profile permissions (environments/ directory contains environment profiles to ensure their permissions are safe: sudo chmod -r 755 environments). This can be done by executing the ./init command.
[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]#