LoginSignup
2
5

More than 3 years have passed since last update.

Forbidden You don't have permission to access this resource出た時の解決策

Last updated at Posted at 2020-02-16

結論

公開ディレクトリ先のvar/www/htmlのhtmlディレクトリの所有者をapacheに変更した

まずは現在の所有者を確認してみる。

[root@ip-172-31-28-29 html]# cd ..

[root@ip-172-31-28-29 www]# pwd
/var/www

[root@ip-172-31-28-29 www]# ls -l
total 0
drwxr-xr-x 2 root     root    6 Oct 22 22:59 cgi-bin
drwxrw-rwx 3 ec2-user apache 51 Feb 15 09:43 html

所有者がec2-userになっていたので今回のエラーが出ていました。

エラー.png

所有者をapacheに変更する

chown -R apache:apache 実行させるフォルダ

[root@ip-172-31-28-29 www]# chown -R apache:apache html

[root@ip-172-31-28-29 www]# ls -l
total 0
drwxr-xr-x 2 root   root    6 Oct 22 22:59 cgi-bin
drwxrw-rwx 3 apache apache 51 Feb 15 09:43 html

[root@ip-172-31-28-29 www]# systemctl restart httpd

これで所有者がapacheに変更しました。
念のためsystemctl restart httpdを行い再起動させましょう。

無事、表示することができました。
apache所有者.png

htmlディレクトリ先のファイルの所有者は?

関係無かったですが、htmlディレクトリ先のファイルの所有者も公開しておきます。

[root@ip-172-31-28-29 html]# pwd
/var/www/html

[root@ip-172-31-28-29 html]# ls -l
total 8
drwxrwxrwx 2 ec2-user ec2-user 19 Feb 15 09:43 test
-rwxrwxrwx 1 ec2-user root     11 Feb 12 23:17 test.html
-rw-r--r-- 1 ec2-user root     22 Feb 14 14:45 test.php
2
5
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
2
5