0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

phpとlinuxパーミッション

Last updated at Posted at 2017-12-11

親ディレクトリは 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();

permission644.png

パーミッション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

permission640.png

ファイル書き込み

# 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

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?