概要
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.
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」を参考に、以下の手順で権限を設定します。

詳細プロフィール。SNS: X Twitter/GS=gnusocialjp@gnusocial.jp/WP=gnusocialjp@web.gnusocial.jp。2022-07-17からgnusocial.jpとweb.gnusocial.jpのサイトを運営しています。WordPressで分散SNSに参加しています。このアカウントの投稿に返信すると、サイトのコメント欄にも反映されます。
Comments