LoginSignup
3
3

More than 5 years have passed since last update.

WordPressをEC2+ELB構成に移行したらハマった(上司が)

Last updated at Posted at 2018-01-16

httpsで運用していたWordPress(4.8.x)を、EC2+ELB構成に移行したときにハマった(上司が)ので、それを記録する。

(上司が)やったこと

  • WordPressソースとテーブルダンプをEC2(& mysql)に展開
  • wp-config.phpに以下の行を追記
$_SERVER['HTTPS'] = 'on';

(上司が)ハマった事象

  • 管理画面にログインすると以下のエラーが表示され、にっちもさっちも行かなくなる
You do not have sufficient permissions to access this admin page.
Reason: The current user doesn't have the "read" capability that is required to access the "ダッシュボード" menu item.

直し方

wp-config.php

$_SERVER['HTTPS'] = 'on';

は、

require_once(ABSPATH . 'wp-settings.php');

より先に書くべし

以上

(追記) $_SERVER['HTTPS'] = 'on'; の推奨すべき書き方

公式リファレンスには、以下のように記載されています。
https://codex.wordpress.org/Function_Reference/is_ssl

if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')
    $_SERVER['HTTPS'] = 'on';
3
3
4

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