[Osaka/Yokohama] Looking for infrastructure/server side engineers!

[Osaka/Yokohama] Looking for infrastructure/server side engineers!

[Deployed by over 500 companies] AWS construction, operation, maintenance, and monitoring services

[Deployed by over 500 companies] AWS construction, operation, maintenance, and monitoring services

[Successor to CentOS] AlmaLinux OS server construction/migration service

[Successor to CentOS] AlmaLinux OS server construction/migration service

[For WordPress only] Cloud server “Web Speed”

[For WordPress only] Cloud server “Web Speed”

[Cheap] Website security automatic diagnosis “Quick Scanner”

[Cheap] Website security automatic diagnosis “Quick Scanner”

[Reservation system development] EDISONE customization development service

[Reservation system development] EDISONE customization development service

[Registration of 100 URLs is 0 yen] Website monitoring service “Appmill”

[Registration of 100 URLs is 0 yen] Website monitoring service “Appmill”

[Compatible with over 200 countries] Global eSIM “Beyond SIM”

[Compatible with over 200 countries] Global eSIM “Beyond SIM”

[If you are traveling, business trip, or stationed in China] Chinese SIM service “Choco SIM”

[If you are traveling, business trip, or stationed in China] Chinese SIM service “Choco SIM”

[Global exclusive service] Beyond's MSP in North America and China

[Global exclusive service] Beyond's MSP in North America and China

[YouTube] Beyond official channel “Biyomaru Channel”

[YouTube] Beyond official channel “Biyomaru Channel”

apache2.4でForbidden連発で消耗したあなたへ

こんにちは。
開発チームのワイルド担当、まんだいです。

久しぶりにapache2.4の設定をやったところ、Forbidden連発で悔しい思いをしたので、試してみた事をまとめました。

 

今回のエラー内容

今回遭遇したエラーはこんな感じです。

[Mon Jun 05 09:45:45.490521 2017] [core:crit] [pid 8125] (13)Permission denied: [client 127.0.0.1:36174] AH00529: /var/www/vhosts/wordpress/.htaccess pcfg_openfile: unable to check htaccess file, ensure it is readable and that '/var/www/vhosts/wordpress/' is executable, referer: http://wp.localhost/readme.html

 

/etc/hostsでwp.localhostというサブドメインを127.0.0.1に振っています。
想像通り、wordpressの開発用サブドメインです。

VirtualBoxで過去に作ったVMを使い回したので、この辺りの設定はすっ飛ばして行けると思ったのに!

今回はVM内のデスクトップ上でEclipseを立ち上げて開発しようと思い、ディスプレイを2枚にするため再起動。
今思えば、ここが良くなかった。

 

今回の解法

小一時間調べて、パーミッション周りの情報しか出てこないな~と思って諦めて帰ろうとしたその矢先、すっかり忘れていたSELinuxの文字が・・・。
こういう時は、素直に

sudo setenforce 0

 

これしかないです。

無事動きました!

再起動した際に、前回実行したsetenforceがリセットされたという訳ですね。
その場しのぎの対応なので、/etc/selinux/config の編集はしないスタンスでした。

そのスタンスを自分で忘れているという、もはやスタンスでもなんでもないという顛末でした。

基本、VMは「状態を保存」で停止するので、VM的にはシャットダウンしてないんですね。

 

他の可能性もある

今回のエラー、常にSELinuxが原因という訳ではないようで、色々な答えが見つかりました。

 

パーミッションが原因の場合

ドキュメントルートのディレクトリ(今回なら、/var/www/vhosts/wordpress/)に、閲覧権限が付いていないので、下層にあるファイルにアクセスできないパターン。

これは、ドキュメントルートのディレクトリで実行権限を追加すれば大丈夫です。

chmod +x /var/www/vhosts/wordpress/

 

こういうパターンもあるんですね。

 

ユーザー権限が原因の場合

これは最初に勘ぐりますね。
でも、だいたいこれじゃない場合が多いです。

そもそも、「770」や「750」みたいなパーミッションでファイル作りませんからね、開発環境では。
「755」「644」を基本に考えていきたいところです。

 

シンボリックリンクが無効になっている

これは、恥ずかしながらたまにありますね。

Options FollowSymlinks を追記します。

気を付けるしかありません。

 

まとめ

今回のケースであれば、httpd.confは以下のような最小構成で行って、なるべく環境構築には手を掛けないで行きたいなと思います。

<VirtualHost wp.localhost:80>
    ServerName wp.localhost
    DocumentRoot /var/www/vhosts/wordpress
    <Directory /var/www/vhosts/wordpress>
        Options FollowSymlinks Includes
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

 

これとSELinuxの設定は絶対忘れたくないと思います。

 
以上です。

この記事がお役に立てば【 いいね 】のご協力をお願いいたします!
0
読み込み中...
0 票, 平均: 0.00 / 10
19,570
X facebook はてなブックマーク pocket
[2024.6.30 CentOS support ended] CentOS server migration solution

[2024.6.30 CentOS support ended] CentOS server migration solution

[2025.6.30 Amazon Linux 2 support ended] Amazon Linux server migration solution

[2025.6.30 Amazon Linux 2 support ended] Amazon Linux server migration solution

[Osaka/Yokohama] Actively recruiting infrastructure engineers and server side engineers!

[Osaka/Yokohama] Actively recruiting infrastructure engineers and server side engineers!

The person who wrote this article

About the author

Yoichi Bandai

My main job is developing web APIs for social games, but I'm also fortunate to be able to do a lot of other work, including marketing.
Furthermore, my portrait rights in Beyond are treated as CC0 by him.