発生した問題

WordPressのローカル環境を作る方法は色々ありますが、今回はをwpーcliとwordmoveを使いたかったのでVagrantベースで作られているVCCWを使ってみようと思い公式サイトの説明に通りにVCCWをセットアップして、Wordmoveの設定をしようとwordmove initを叩いたら、そんなコマンドはないと怒られました。

原因と解決方法

実際にどのようなことが起きたかは後述いたしますが、結論から書きます。

原因:Rubyのバージョンが古くWordmoveがインストールされなかった
解決方法:対応するRubyのバージョンをインストールして設定

終わってみればしょうもない原因でした。

問題発生と解決までの経緯

VCCWのセットアップ

VCCWをセットアップするには下記の2つのツールが必要です。

  • Vagrant
  • VirtualBox

Vagrantのプラグインであるvagrant-hostsupdaterを入れておくといい感じにホストをいじってくれるらしいです。
インストール前に下調べをしたところ下記が主に参考になりました。

VirtualBoxとVagrantはすでに環境に入っていたので、vagrant-hostsupdaterをインストールして、
必要なvagrant boxをダウロードします。

$ vagrant plugin install vagrant-hostsupdater
$ vagrant box add vccw-team/xenial64

続いて公式サイトからVCCWのZIPをダウンロードします。

VCCWのリポジトリをクローンする方法でも使えるらしいですが、
作者の方がZIP アーカイブをダウンロードして使うのを強く推奨します!
と言っておられるので素直にZIPアーカイブを使いました。

理由は

リポジトリには VCCW そのものを開発するためのテストコード等も含まれます。これらは多くの場合みなさんには不要です。
具体的にどのクライアントかは把握していませんが、一部の Windows 用 Git クライアントは改行コードを変換するようです。この場合、プロビジョニングがうまくいきません。

VCCWとの上手な付き合い方

さて、セットアップに戻ります。
ZIPを解凍し、そのディレクトリに移動してVagrantを起動します。

$ cd vccw 
$ vagrant up

http://vccw.test/ か http://192.168.33.10/ にアクセスして、サイトが表示されていることを確認します。

また、site.ymlを利用することで言語設定やホスト名、プラグインのインストールをしておくこともできます!便利!

Wordmoveの設定

ローカル環境ができたので、本番環境と同期させるためにWordmoveの設定をします。

Wordmoveを利用すると本番環境をまるっとpullしたり、ローカル環境で変更を加えたプラグインだけとかテーマだけをpushするとかもコマンドから操作できるようになると知ってこれは使いたいとなりました!

もうFTPは使えない! WordPressのデプロイはWordmoveで決まり!

VCCWにはWordmoveが同梱されており、Movefile.ymlを編集することで設定できます。

設定の参考になりそうな記事をいくつかピックアップしました。

WordPress本番環境とローカル環境を超簡単に同期するWordMoveの設定&使い方
本番環境のWordPressサイトを『VCCW+WordMove』でローカルと同期する方法
Wordmoveでローカルと本番のWordPressを同期しよう

記事を参考にしてMovefileを編集しようと思いましたがMovefileが見当たりません。initすると書いてある記事もあるので、やってみました。

vccw $ wordmove init 
zsh: command not found: wordmove

あれ、、、wordmoveない…
おかしいな?入れるところからか

vccw $ gem install wordmove 
Fetching: concurrent-ruby-1.1.5.gem (100%) 
ERROR:  While executing gem ... (Gem::FilePermissionError) 
    You don't have write permissions for the /Library/Ruby/Gems/2.3.0 directory.

権限がないと怒れれたので、

vccw $ sudo gem install wordmove 
Password:

パスワードを入力して、

Fetching: concurrent-ruby-1.1.5.gem (100%) 
Successfully installed concurrent-ruby-1.1.5 
Fetching: i18n-1.6.0.gem (100%) 
 
HEADS UP! i18n 1.1 changed fallbacks to exclude default locale. 
But that may break your application. 
 
Please check your Rails app for 'config.i18n.fallbacks = true'. 
If you're using I18n (>= 1.1.0) and Rails (< 5.2.2), this should be 
'config.i18n.fallbacks = [I18n.default_locale]'. 
If not, fallbacks will be broken in your app by I18n 1.1.x. 
 
For more info see: 
 
 
Successfully installed i18n-1.6.0 
Fetching: thread_safe-0.3.6.gem (100%) 
Successfully installed thread_safe-0.3.6 
Fetching: tzinfo-1.2.5.gem (100%) 
Successfully installed tzinfo-1.2.5 
Fetching: activesupport-5.2.3.gem (100%) 
Successfully installed activesupport-5.2.3 
Fetching: colorize-0.8.1.gem (100%) 
Successfully installed colorize-0.8.1 
Fetching: dotenv-2.2.2.gem (100%) 
Successfully installed dotenv-2.2.2 
Fetching: kwalify-0.7.2.gem (100%) 
Successfully installed kwalify-0.7.2 
Fetching: net-ssh-4.2.0.gem (100%) 
Successfully installed net-ssh-4.2.0 
Fetching: net-ssh-gateway-2.0.0.gem (100%) 
Successfully installed net-ssh-gateway-2.0.0 
Fetching: net-sftp-2.1.2.gem (100%) 
Successfully installed net-sftp-2.1.2 
Fetching: net-scp-1.2.1.gem (100%) 
Successfully installed net-scp-1.2.1 
Fetching: photocopier-1.3.2.gem (100%) 
ERROR:  Error installing wordmove: 
    photocopier requires Ruby version >= 2.4.0.

内部で使用しているgemをインストールするのにはRubyのバージョンが2.4.0以上の必要があるようです。
VCCWに入っているはずのWordmoveがなかったのもこれが原因と思われます。

Rubyのバージョンを確認します。

vccw $ ruby -v 
ruby 2.3.7p456 (2018-03-28 revision 63024) [universal.x86_64-darwin18]

確かにバージョンが足りてないですね。
rbenv(Rubyのバージョン管理ツール)でインストール可能なバージョンを調べます。

~ $ rbenv install -l 

今回は2.6.3をインストールすることにしました。

~ $ rbenv install 2.6.3 
ruby-build: using openssl from homebrew 
Downloading ruby-2.6.3.tar.bz2... 
-> https://cache.ruby-lang.org/pub/ruby/2.6/ruby-2.6.3.tar.bz2 
Installing ruby-2.6.3... 
ruby-build: using readline from homebrew 
Installed ruby-2.6.3 to /Users/username/.anyenv/envs/rbenv/versions/2.6.3

インストールしたバージョンを使えるようにします。

~ $ rbenv rehash 

インストールしたバージョンをセットします。
今回はグローバルに設定しましたが、ローカルでもいいと思います。

~ $ rbenv global 2.6.3

vccwのディレクトリに移動してから、改めてWordmoveのインストールを試みます。

vccw $ sudo gem install wordmove 
ERROR:  Error installing wordmove: 
    photocopier requires Ruby version >= 2.4.0.

あれれ、、、もしや、、、

vccw $ ruby -v 
ruby 2.3.7p456 (2018-03-28 revision 63024) [universal.x86_64-darwin18]

シェルの再起動をします。

vccw $ exec $SHELL -l 
vccw $ ruby -v 
ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-darwin18]

今度こそ!

vccw $ sudo gem install wordmove 
Fetching i18n-1.6.0.gem 
Fetching tzinfo-1.2.5.gem 
Fetching concurrent-ruby-1.1.5.gem 
Fetching colorize-0.8.1.gem 
Fetching dotenv-2.2.2.gem 
Fetching thread_safe-0.3.6.gem 
Fetching kwalify-0.7.2.gem 
Fetching activesupport-5.2.3.gem 
Fetching net-ssh-4.2.0.gem 
Fetching net-ssh-gateway-2.0.0.gem 
Fetching net-sftp-2.1.2.gem 
Fetching net-scp-1.2.1.gem 
Fetching photocopier-1.3.2.gem 
Fetching thor-0.19.4.gem 
Fetching wordmove-4.0.1.gem 
Successfully installed concurrent-ruby-1.1.5 
 
HEADS UP! i18n 1.1 changed fallbacks to exclude default locale. 
But that may break your application. 
 
Please check your Rails app for 'config.i18n.fallbacks = true'. 
If you're using I18n (>= 1.1.0) and Rails (< 5.2.2), this should be 
'config.i18n.fallbacks = [I18n.default_locale]'. 
If not, fallbacks will be broken in your app by I18n 1.1.x. 
 
For more info see: 
 
 
Successfully installed i18n-1.6.0 
Successfully installed thread_safe-0.3.6 
Successfully installed tzinfo-1.2.5 
Successfully installed activesupport-5.2.3 
Successfully installed colorize-0.8.1 
Successfully installed dotenv-2.2.2 
Successfully installed kwalify-0.7.2 
Successfully installed net-ssh-4.2.0 
Successfully installed net-ssh-gateway-2.0.0 
Successfully installed net-sftp-2.1.2 
Successfully installed net-scp-1.2.1 
Successfully installed photocopier-1.3.2 
Successfully installed thor-0.19.4 
    Starting from version 3.0.0 `database.charset` option is no longer accepted. 
    Pass the '--default-charecter-set' flag into `database.mysqldump_options` or to 
    `database.mysql_options` instead, if you need to set the same option. 
 
    Starting from version 3.0.0 the default `global.sql_adapter` is "wpcli". 
    Therefor `WP-CLI` becomes a required peer dependency, unless you'll 
    change to the "default" adapter. 
Successfully installed wordmove-4.0.1 
Parsing documentation for concurrent-ruby-1.1.5 
Installing ri documentation for concurrent-ruby-1.1.5 
Parsing documentation for i18n-1.6.0 
Installing ri documentation for i18n-1.6.0 
Parsing documentation for thread_safe-0.3.6 
Installing ri documentation for thread_safe-0.3.6 
Parsing documentation for tzinfo-1.2.5 
Installing ri documentation for tzinfo-1.2.5 
Parsing documentation for activesupport-5.2.3 
Installing ri documentation for activesupport-5.2.3 
Parsing documentation for colorize-0.8.1 
Installing ri documentation for colorize-0.8.1 
Parsing documentation for dotenv-2.2.2 
Installing ri documentation for dotenv-2.2.2 
Parsing documentation for kwalify-0.7.2 
Installing ri documentation for kwalify-0.7.2 
Parsing documentation for net-ssh-4.2.0 
Installing ri documentation for net-ssh-4.2.0 
Parsing documentation for net-ssh-gateway-2.0.0 
Installing ri documentation for net-ssh-gateway-2.0.0 
Parsing documentation for net-sftp-2.1.2 
Installing ri documentation for net-sftp-2.1.2 
Parsing documentation for net-scp-1.2.1 
Installing ri documentation for net-scp-1.2.1 
Parsing documentation for photocopier-1.3.2 
Installing ri documentation for photocopier-1.3.2 
Parsing documentation for thor-0.19.4 
Installing ri documentation for thor-0.19.4 
Parsing documentation for wordmove-4.0.1 
Installing ri documentation for wordmove-4.0.1 
Done installing documentation for concurrent-ruby, i18n, thread_safe, tzinfo, activesupport, colorize, dotenv, kwalify, net-ssh, net-ssh-gateway, net-sftp, net-scp, photocopier, thor, wordmove after 9 seconds 
15 gems installed

インストールできたようですので、

vccw $ wordmove init 
      create  movefile.yml 

できました!

rbenvは入れていたもののほぼ使ってなかったので、下記の記事を参考にさせて頂きました。

rbenvでRubyのバージョンを最新安定版にupdate
rbenvの使い方と仕組みについて

この記事を書いた人

Yuki Tomioka

元焼肉店店長からゼロシード株式会社の1人目のwebエンジニアとなる。テクニカルディレクターとして勤務し、WordPressのカスタマイズやアクセス解析や広告運用などに従事。現在は事業会社のフロントエンドエンジニアとして勤務。
タイムチケットで相談も受け付けてます。