質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%

Q&A

解決済

2回答

470閲覧

 LAMP環境で403 Forbiddenエラー

Yakusugi

総合スコア123

0グッド

1クリップ

投稿2022/09/15 06:48

編集2022/09/15 09:08

自宅に設置したPCにUbuntu Server 20.04をインストールし、Linuxの学習も兼ねて個人的にLAMPサーバ構築を進めております。
SQL文を記述したPHPは既に用意(/var/www/android)しており、当該PHP(select_sample.php)をMySQLにアクセスするためのAPIとして構築しています。
やりたい事は、ブラウザからhttp://[ip address]/select_sample.phpへアクセスし、当該PHPファイルに記述されたSQLを発行し、ブラウザに表示させる事です。
※/var/www/androidは今回の個人プロジェクト用に作成したディレクトリになります。

今回、上記一連のLAMP環境を構築し、ブラウザからhttp://[ip address]/select_sample.phpへアクセスを試みたところ、
添付画像にもある通り、下記のように403エラー(Forbidden)が発生してしまいました。
Forbidden
You don't have permission to access this resource.
イメージ説明

本来であれば、上記でアクセスしたselect_sample.phpに記述されたselect文が実行され、
当該実行結果がブラウザに表示されるはずでした。

従いまして、上記エラーを解決して頂ける方を探しております。
今回のエラーはLinuxの権限周りのエラーかと思いますので、Linux関連に関してお詳しい方がいればご回答の程よろしくお願いいたします。

参考までに下記に上記以外の設定も記述します:
/var/www/androidはapacheのdoument rootに指定しております。

<VirtualHost *:80>
ServerName android.dev
ServerAdmin webmaster@localhost
DocumentRoot /var/www/android
ErrorLog ${APACHE_LOG_DIR}error.log
CustomLog ${APACHE_LOG_DIR}access.log combined

<Directory /var/www/android>
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>

またselect_sample.phpはdocument root直下(/var/www/android)に置いてあります。
イメージ説明

エラーログを確認した所、下記のようなログが吐き出されていました。
AH01630: client denied by server configuration: /var/www/html/select_sample.php

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

okakemetal

2022/09/15 07:49

エラーメッセージの意味は「アクセス権限を持っていませんよ」という内容になりますので 関連するファイルの所有者やグループ、アクセス権限などをご確認ください
AbeTakashi

2022/09/15 07:52 編集

このような不具合が出た場合、まずはこのエラーが発生した際のApacheのエラーログの内容を参照してください。403なので権限エラーなのはほぼ間違いないですが、具体的にどのような理由でそのエラーが発生してるかがログにちゃんと書いてある場合があります。ログを見ても解決が難しい場合は、質問文内にそのエラーログの内容を追記してください。第三者が状況だけでエラーの理由を具体的に指摘するのはおそらく難しいです。
Yakusugi

2022/09/15 08:55

上記、ご指摘頂きありがとうございます。 先ほど、質問文の方も編集しましたが、 エラー内容は下記の通りでした。 AH01630: client denied by server configuration: /var/www/html/select_sample.php
otn

2022/09/15 09:01 編集

> Linuxの権限周りのエラーかと思いますので ですが、 > Linuxの学習も兼ねて ということであれば、ファイルのアクセス権というのは極初歩の基本なので、学習された方が良いかと思います。
AbeTakashi

2022/09/15 08:59

「Client denied by server configuration 原因」などでググると原因とか対応方法が色々と出てきます。まずはそちらに目を通して、原因を絞り込んでいってください。/var/www/html/select_sample.php もヒントになると思います。サーバの中の状況は第三者には分からないので、ご自身で頑張って絞り込むしかないかと思います。
otn

2022/09/15 09:02

新情報があったので、訂正ですが、 > client denied by server configuration なので、 > Linuxの権限周りのエラーかと思いますので じゃなくて、Apacheの設定が原因ですね。
Yakusugi

2022/09/15 09:09

/var/www/androidのapacheの設定が原因との事だったので、調べてみて、下記のように修正してみましたが、結果は変わらずです。。。 <VirtualHost *:80> ServerName android.dev ServerAdmin webmaster@localhost DocumentRoot /var/www/android ErrorLog ${APACHE_LOG_DIR}error.log CustomLog ${APACHE_LOG_DIR}access.log combined <Directory /var/www/android> Options FollowSymLinks AllowOverride All Require all granted </Directory> </VirtualHost>
otn

2022/09/15 14:00

<VirtualHost *:80> のセクションは、設定ファイル全体でこの一箇所のみですか?
Yakusugi

2022/09/16 00:46

はい、<VirtualHost *:80> のセクションは当該設定ファイル(android.dev.conf)全体でこの1か所のみです。 <VirtualHost *:80> ServerName android.dev ServerAdmin webmaster@localhost DocumentRoot /var/www/android ErrorLog ${APACHE_LOG_DIR}error.log CustomLog ${APACHE_LOG_DIR}access.log combined <Directory /var/www/android> Options FollowSymLinks AllowOverride All Require all granted </Directory> </VirtualHost>
otn

2022/09/16 03:37 編集

> はい、<VirtualHost *:80> のセクションは当該設定ファイル(android.dev.conf)全体でこの1か所のみです。 いや、そういう質問じゃなくて、「(当該設定ファイル以外も含めて)全体で1カ所ですか?」という質問です。
Yakusugi

2022/09/16 04:00

調べたら、android.dev.conf以外では、000-default.confにも記載がありました。 元々、android.dev.confは000-default.confを元にしていたので。 <VirtualHost *:80> # The ServerName directive sets the request scheme, hostname and port that # the server uses to identify itself. This is used when creating # redirection URLs. In the context of virtual hosts, the ServerName # specifies what hostname must appear in the request's Host: header to # match this virtual host. For the default virtual host (this file) this # value is not decisive as it is used as a last resort host regardless. # However, you must set it for any further virtual host explicitly. #ServerName www.example.com ServerAdmin webmaster@localhost DocumentRoot /var/www/html # Available loglevels: trace8, ..., trace1, debug, info, notice, warn, # error, crit, alert, emerg. # It is also possible to configure the loglevel for particular # modules, e.g. #LogLevel info ssl:warn ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined # For most configuration files from conf-available/, which are # enabled or disabled at a global level, it is possible to # include a line for only one particular virtual host. For example the # following line enables the CGI configuration for this host only # after it has been globally disabled with "a2disconf". #Include conf-available/serve-cgi-bin.conf </VirtualHost> # vim: syntax=apache ts=4 sw=4 sts=4 sr noet
guest

回答2

0

自己解決

000-default.confのDocumentRoot /var/www/androidの部分を修正することで解決しました。

<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com

ServerAdmin webmaster@localhost DocumentRoot /var/www/android # Available loglevels: trace8, ..., trace1, debug, info, notice, warn, # error, crit, alert, emerg. # It is also possible to configure the loglevel for particular # modules, e.g. #LogLevel info ssl:warn ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined # For most configuration files from conf-available/, which are # enabled or disabled at a global level, it is possible to # include a line for only one particular virtual host. For example the # following line enables the CGI configuration for this host only # after it has been globally disabled with "a2disconf". #Include conf-available/serve-cgi-bin.conf
</VirtualHost>

投稿2022/10/10 02:49

Yakusugi

総合スコア123

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

0

調べたら、android.dev.conf以外では、000-default.confにも記載がありました。

ホスト名部分をIPアドレスで指定した場合、ServerName IPアドレスと書いたVirtualhostセクションが無いと、デフォルトのVirtualhostセクション(全設定ファイルの中の最初のもの)が採用されます。
つまりドキュメントルートは/var/www/htmlです。

そこにアクセス権が無いなどで、403が返っているのでしょう。
<Directory /var/www><Directory /var/www/html>/var/www/html/.htaccessの内容など。

なお、

全設定ファイルの中の最初のもの

ですが、設定ファイルは、IncludeOptional conf.d/*.confで読まれているのでしょうから、文字コード順です。

投稿2022/09/16 04:18

otn

総合スコア84555

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

Yakusugi

2022/09/16 04:42

回答ありがとうございます。 ご回答の中で「ホスト名部分をIPアドレスで指定した場合、ServerName IPアドレスと書いたVirtualhostセクションが無いと、デフォルトのVirtualhostセクション(全設定ファイルの中の最初のもの)が採用されます。」とありましたが、 大変恐縮なのですが、私の知識不足のせいで理解しきれておりません。 下記、設定ファイルを列挙してみたのですが、どこに不備があるのかがまだ見えてきておりません。 お手数ではあるのですが、もう少しヒントを頂けないでしょうか。 よろしくお願いいたします。 /etc/apache2/sites-available/android.dev.conf <VirtualHost *:80> ServerName android.dev ServerAdmin webmaster@localhost DocumentRoot /var/www/android ErrorLog ${APACHE_LOG_DIR}error.log CustomLog ${APACHE_LOG_DIR}access.log combined <Directory /var/www/android> Options FollowSymLinks AllowOverride All Require all granted </Directory> </VirtualHost> /etc/apache2/apache2.conf <Directory /> Options FollowSymLinks AllowOverride None Require all denied </Directory> <Directory /usr/share> AllowOverride None Require all granted </Directory> <Directory /var/www/android> Options Indexes FollowSymLinks AllowOverride None Require all granted </Directory> /etc/hosts 127.0.0.1 localhost android.dev 127.0.1.1 skynew_ubuntu_server # The following lines are desirable for IPv6 capable hosts ::1 ip6-localhost ip6-loopback fe00::0 ip6-localnet ff00::0 ip6-mcastprefix ff02::1 ip6-allnodes ff02::2 ip6-allrouters
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問