Apache HTTP Serverの/var/wwwの権限設定

develop/server
概要

OSのパッケージマネージャーでApache HTTP Serverをインストールすると、デフォルトで/var/www/htmlがDocumentRoot (公開ディレクトリー) になっていることが多いです。

ただ、ファイルの配置などで実際に作業しようとすると、/var/wwwのアクセス権限がrootになっていて作業しにくいです。

アクセス権限設定について調べたので紹介します。

5.8. Securing Apache」にデフォルトのアクセス権限について以下の記載がありました。

5.8.3. Published web files
Apache files are located under /var/www. Just after installation the default file provides some information on the system (mainly that it’s a Debian system running Apache). The default webpages are owned by user root and group root by default, while the Apache process runs as user www-data and group www-data. This should make attackers that compromise the system through the web server harder to deface the site. You should, of course, substitute the default web pages (which might provide information you do not want to show to outsiders) with your own.
5.8. Securing Apache

Debian系OSでは、/var/wwwはユーザー=root、グループ=rootにより所有されています。Apacheプロセスはユーザー=www-data、グループ=www-dataとして実行されます。rootユーザーのみが書き込み可能で、それ以外からはApache含めて書き込み不能になっています。

これは、例えばWordPressなどのApache上で動作するWebアプリからのファイルアップロードもできないことを意味します。したがって、何かしらの権限設定の変更が必要です。

対応

Apacheプロセスのユーザーがわかったので、「チュートリアル: Amazon Linux 2022 に LAMP ウェブサーバーをインストールする – Amazon Elastic Compute Cloud」を参考に、以下の手順で権限を設定します。

この投稿は Gold and Silver の会員限定 (月額Free=0円、Silver=1100円、Gold=3300円) です。記録が目的であり、元投稿の削除・炎上回避、運営費・GNU socialの開発資金などのため会員限定にしています。

このサイトでは分散SNSの話題を1年以上毎日更新しており、情報量、更新頻度は日本一だと思います。最新動向・詳細情報を把握したい人は、会員登録/ログインをお願いします (About Member)。

Comments

Copied title and URL