ローカル環境:local by Flywheel ( https://local.getflywheel.com/ )
本番環境:Cloudways ( https://www.cloudways.com/en/ )・ Wordmove : https://github.com/welaika/wordmove
ステージング・プロダクション環境とローカル環境を同期できる gem
・ WP-CLI: https://wp-cli.org/ja/
WordPress管理をいろいろコマンド操作できる(local by Flywheel についてる)
今回は、local by Flywheel でローカル環境を整え、Cloudways で本番環境を運営しているパターンです。
- wordmove gem をインストール
$ gem install wordmove
- wordpress 本体に移動
$ cd /Users/~hoge~/app/public
- wordpress 本体直下に
movefile.yml
を作成
$ wordmove init
Flywheel Database・Site Seup タブ箇所を参考に movefile.yml
の設定を確認
localのMysqlに接続できなくてつまずいたところ( local database 設定箇所の host は Flywheel の DATABASEタブ箇所の Remote Host IP に変更し、Remote Portの番号をport設定に追加してあげたら接続でけた )
movefile.yml
// 開発環境設定(ローカル)
local:
vhost: "http://hoge.local"
wordpress_path: "/Users/~hoge~/app/public" # use an absolute path here (絶対パス)
database:
name: "database_name"
user: "user"
password: "password"
host: "0.0.0.0" # Remote Host IP (リモートホストのIP)
port: "0000" # Remote Port number (リモートポートの番号)
charset: "utf8"
mysqldump_options: "--column-statistics=0" # Mysql バージョン 8系からエラーが出るので追加
// 本番環境設定(プロダクション)
production:
vhost: "http://hoge.com"
wordpress_path: "/var/www/your_site" # use an absolute path here (絶対パス)
database:
name: "database_name"
user: "user"
password: "password"
host: "host"
charset: "utf8"
port: 3306 # Use just in case you have exotic server config
# mysqldump_options: '--max_allowed_packet=1G' # Only available if using SSH
# mysql_options: '--protocol=TCP' # mysql command is used to import db
ssh:
host: "host"
user: "user"
port: 00
本番環境の確認
cloudways hostの確認場所 – servers page
cloudways databaseの確認場所 hostもあった – application page
sshの設定
ここらへんを参考に
【mac】SSH鍵認証でサーバに接続する(初級編)
http://cameong.hatenablog.com/entry/2017/02/17/011429
設定を完了させたらいよいよ wordmove!
movefile.yml
を置いたローカルのwordpress本体ディレクトリに移動
$ cd /Users/~hoge~/app/public
wordmove cmd
// オプションを付けて各種pull・pushする
// 本番環境からデータベースやアップロードファイルを取得(プル)
$ wordmove pull -d -u
// ローカルから本番環境にテーマをアップロード(プッシュ)
$ wordmove push -t
// pull・push オプション( wordmove pull -d だとDBのみを取得 )
Options:
-w, [--wordpress], [--no-wordpress]
-u, [--uploads], [--no-uploads]
-t, [--themes], [--no-themes]
-p, [--plugins], [--no-plugins]
-m, [--mu-plugins], [--no-mu-plugins]
-l, [--languages], [--no-languages]
-d, [--db], [--no-db]
-v, [--verbose], [--no-verbose]
-s, [--simulate], [--no-simulate]
-e, [--environment=ENVIRONMENT]
-c, [--config=CONFIG]
[--debug], [--no-debug]
[--no-adapt], [--no-no-adapt]
[--all], [--no-all]
// ヘルプ
$ wordmove help
Commands:
wordmove --version, -v # Print the version
wordmove doctor # Do some local configuration and environment checks
wordmove help [TASK] # Describe available tasks or one specific task
wordmove init # Generates a brand new movefile.yml
wordmove pull # Pulls WP data from remote host to the local machine
wordmove push # Pushes WP data from local machine to remote host
と思ったらエラーが出たんだよ。
Error: Error establishing a database connection.This either means that the username and password information in your `wp-config.php`file is incorrect or we can’t contact the database server at `localhost`. This could mean your host’s database server is down.
wp-config.php
の DB_HOST を movefile.yml
に設定した remotehost とremote post に変更したらやっとこいけました。
/** MySQL hostname */
define( 'DB_HOST', '0.0.0.0:0000' );
でけたー!!本番環境との同期を確認でけたー!
今回は本番からデータベースのデータをpullしました。
コマンド間違ったりしないように、バッチファイルを作ってみようとおもいます!
うまくいかない時は
$ wordmove doctor
参考資料 ーーーーーーーーーーーーーーー
デフォルト movifile.yml
https://github.com/welaika/wordmove
参考POST:Wordmove の正しい設定方法
https://qiita.com/miya0001/items/9217140161216bbefc19