親ディレクトリは r-x
# ls -l
合計 4
drwxr-xr-x 2 root root 6 12月 12 21:53 default_dir
-rw-r--r--. 1 root root 18 12月 11 22:23 index.php
drw-r--r-x. 2 root root 53 12月 12 00:14 public
# sudo tree
.
├── default_dir
├── index.php
└── public
├── default_permission.php
└── index.php
パーミッションrw- r--
sudo chmod -R o=rw public
sudo chmod -R o=r public
error nginx403
sudo chmod -R o=x public
error nginx access denied
php実行
# ls -l
-rw-r--r-- 1 root root 0 12月 12 00:12 default_permission.php
-rw-r--r-- 1 root root 17 12月 12 00:14 index.php
右3文字の r--
の r
がいる でphp実行できる
# cat index.php
<?php
phpinfo();
パーミッション640
Access denied.
# chmod 640 index.php
# ls -l
合計 4
-rw-r--r-- 1 root root 0 12月 12 00:12 default_permission.php
-rw-r----- 1 root root 17 12月 12 00:14 index.php
ファイル書き込み
# tree
.
├── default_permission.php
├── file.php
├── index.php
└── test.txt
# ls -l
-rw-r--r-- 1 root root 70 12月 12 22:13 file.php
-rw-r--r-- 1 root root 0 12月 12 22:12 test.txt
# cat file.php
<?php
$filename = 'test.txt';
file_put_contents($filename, 'test');
error
*19 FastCGI sent in stderr: "PHP message: PHP Warning: file_put_contents(test.txt): failed to open stream: Permission denied in /var/www/laravel/public/file.php on line 5" while reading response header from upstream, client: 10.0.0.6, server: 10.0.0.8, request: "GET /file.php HTTP/1.1", upstream: "fastcgi://unix:/var/run/php-fpm/php-fpm.sock:", host: "10.0.0.8"
sudo chmod -R ug+rw test.txt
sudo chown -R nginx:nginx test.txt
OK