7
4

More than 1 year has passed since last update.

トラブル事案|AWS-LightsailのWordPress(bitnami)で failed to open stream: Permission denied が出た場合

Last updated at Posted at 2021-12-09

どんな環境でおきたか

  • AWS-LightsailでWordPress(bitnami)を使っていた
  • テストサーバーで構築していたWPのファイル一式を、本番環境(AWS-Lightsail)へ移行した(ファイル一式をFTPクライアント経由で上書きアップロード)
  • WordPress の更新をした際に、下記のエラーが表示された(更新が出来なかった)

Warning: copy(/opt/bitnami/wordpress/wp-content/languages/ja-******.json): failed to open stream: Permission denied in /opt/bitnami/wordpress/wp-admin/includes/class-wp-filesystem-direct.php on line 309

Warning: chmod(): Operation not permitted in /opt/bitnami/wordpress/wp-admin/includes/class-wp-filesystem-direct.php on line 173

解決方法:パーミッションの再設定

Files and directories are owned by user bitnami and group daemon.
Directories are configured with permissions 775 by default.
Files are configured with permissions 664 by default.
The wp-config.php file is configured with permissions 640.

ファイルとディレクトリの所有者は、ユーザーのbitnamiとグループのdaemonです。
ディレクトリのパーミッションは、デフォルトでは775に設定されています。
ファイルのパーミッションは、デフォルトでは664に設定されています。
wp-config.phpファイルのパーミッションが640に設定されています。

ディレクトリの場所の確認

image.png

  • 2021年12月現在、bitnamiのWordPressは、ディレクトリが2箇所に分かれて配置されています。
  • WordPress本体部は/opt/bitnami/wordpress/にあります。
  • ユーザーが触りそうなファイルなどは/bitnami/wordpress/にあります。

パーミッションの変更

  • 今回は、ファイルwp-config.phpおよびディレクトリwp-contentのパーミッションの一括変更を記します。
terminal
$ cd /bitnami  # ディレクトリ[bitnami]へ移動

$ sudo chown -R bitnami:daemon wordpress  # ディレクトリ[wordpress]以下の所有者:グループを一括変更

$ sudo find wordpress -type d -exec chmod 775 {} \;  # ディレクトリ[wordpress]以下のディレクトリのパーミッションを775へ一括変更

$ sudo find wordpress -type f -exec chmod 664 {} \;  # ディレクトリ[wordpress]以下のファイルのパーミッションを664へ一括変更

$ sudo chmod 640 wordpress/wp-config.php  # ファイル[wp-config.php]のパーミッションを640へ変更

image.png

以上で、問題解決しました(WordPress の更新がエラーなく出来るようになりました)

考察:何故この事態になったのか

  • ディレクトリwp-content/plugins以下、あるプラグインの一部ディレクトリのパーミッションが755になっておりました。
  • テスト環境においてのプラグインのインストールの仕方がまずかったのか、それとも本番環境へのアップロードの仕方が悪かったのか...
  • パーミッション問題とか所有者問題とか...引っかかると面倒ですよね...

誰かのお役に立てば幸いです

7
4
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
7
4