0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Wordpressのステージング環境を作る(Xサーバー)

Posted at

1. 検証用のサブドメインを作成

  1. Xサーバーのサーバーパネルにログイン
  2. 「ドメイン」→「サブドメイン設定」を開く
  3. 本番サイトのドメインを選択し、サブドメインを追加(ex. staging.example.com)
  4. 追加後、FTPや、ファイルマネージャー、ssh接続などで、「staging.example.com」用のフォルダが作成されていることを確認

2. 本番のWordPressファイルをコピー

WordPressのファイルはpublic_html/以下に入ってます。

  1. 本番のWP関連ファイル(public_html/example.com)をコピーして、
  2. 検証環境(public_html/staging.example.com)にペースト
  3. wp-config.php の DB_NAME, DB_USER, DB_PASSWORD の本番用DBをメモする。

3. データベースをコピー

  1. 本番のDBをエクスポート
    • phpMyAdimnで本番のDBを開く
      ( wp-config.phpで確認した本番用の DB_USERDB_PASSWORDでログインする)
    • エクスポートタブから「SQL形式」でダウンロード
       
  2. 検証用のDBを作成
    • Xサーバーの「MySQL設定」→「MySQL追加」から新しいDBを作成
    • MySQLユーザーも割り当てる
       
  3. 検証用DBにインポートする
    • phpMyAdimnで検証用DBを開く(2で作成したDBのユーザー名、パスワードでログイン)
    • インポートタブから先ほどのSQLファイルをアップロード

4. DBの接続先を変える。

wp-config.php の DB_NAME, DB_USER, DB_PASSWORD を新しく作った検証用DBに変える

5. URLを書き換える。

データベースには「本番のURL」が入っているので、「検証用のURL」に変更する。
DBデータの文字列置換によく使われるツールは
https://github.com/interconnectit/Search-Replace-DB

6. 本番と同じパスワードで管理画面に入る、完成🎉

7. おまけ

本番と管理画面が同じだと、わかりにくいので、

functions.php
// 全ユーザーの管理画面カラースキームを「blue」に強制
function set_default_admin_color($user_id) {
  $args = array(
    'ID' => $user_id,
    'admin_color' => 'ectoplasm' // other options: fresh, light, blue, coffee, ectoplasm, midnight, ocean, sunrise
  );
  wp_update_user($args);
}
add_action('user_register', 'set_default_admin_color');

// 既存ユーザーも含めて一括で変更(初回だけ実行してOK)
function force_admin_color_for_all_users() {
  $users = get_users();
  foreach ($users as $user) {
    update_user_meta($user->ID, 'admin_color', 'ectoplasm');
  }
}
force_admin_color_for_all_users();

こんな感じで背景色を変えると目視で区別しやすい。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?