WP-CLIでWordPressコアをアップデートすると、WP-CLI自身もアップデートしないとコマンドエラーが起こることがある。WP-CLIでWordPressコアを操作するのだから両方のバージョンの互換性を合わせないとエラー起こるのも当然ですね。WP-CLIを最新版で再インストールとか面倒な作業してたらコマンドあるよ!ってアドバイスもらったのでコマンド調べたのをまとめました。普通にヘルプみたらありましたね。なぜ気づかなったんだろ・・・
wp help
WP CLIには便利なhelpコマンドがあるのでCLI関連のコマンドを調査!これがあるのでリファレンスサイトへアクセスする必要もないのですごく助かる!
[vagrant@vccw ~]$ wp help NAME wp DESCRIPTION Manage WordPress through the command-line. SYNOPSIS wpSUBCOMMANDS cache Manage the object cache. cap Manage user capabilities. cli Get information about WP-CLI itself. comment Manage comments. core Download, install, update and otherwise manage WordPress proper. 略
サブコマンドに「cli:WP-CLI自身についての情報取得」がちゃんとありますね。
wp help cli
サブコマンド cli も helpコマンドで調べてみます。
[vagrant@vccw ~]$ wp help cli wp cli DESCRIPTION Get information about WP-CLI itself. SYNOPSIS wp cliSUBCOMMANDS check-update Check for update via Github API. Returns the available versions if there are updates, or empty if no update available. cmd-dump Dump the list of installed commands, as JSON. completions Generate tab completion strings. info Print various data about the CLI environment. param-dump Dump the list of global parameters, as JSON or in var_export format. update Fetch most recent update matching the requirements. Returns the available versions if there are updates, or empty if no update available. version Print WP-CLI version.
wp cli version
まずは、現在のバージョンを調べてみます。
[vagrant@vccw ~]$ wp cli version WP-CLI 0.22.0 [vagrant@vccw ~]$
バージョンが 0.22.0 であることが確認できました。
wp cli check-update
WP-CLIの更新対象があるか確認してみます。
[vagrant@vccw ~]$ wp cli check-update +---------+-------------+-------------------------------------------+ | version | update_type | package_url | +---------+-------------+-------------------------------------------+ | 0.23.0 | minor | https://github.com/wp-cli/wp-cli/releases | | | | /download/v0.23.0/wp-cli-0.23.0.phar | +---------+-------------+-------------------------------------------+ [vagrant@vccw ~]$
最新バージョンが 0.23.0 であることが確認できました。
wp cli update
最新にアップデートします。WP-CLIをrootでインストールしていると少し躓きました。躓いた内容も少し載せてます。
[vagrant@vccw ~]$ wp cli update Error: /usr/share/wp-cli/phar/wp-cli.phar is not writable by current user [vagrant@vccw ~]$
まずrootでないユーザでアップデートしようとすると「現在のユーザで保存されていない!」と怒られました。
[vagrant@vccw ~]$ su Password: [root@vccw vagrant]# wp cli update Error: YIKES! It looks like you're running this as root. You probably meant to run this as the user that your WordPress install exists under. If you REALLY mean to run this as root, we won't stop you, but just bear in mind that any code on this site will then have full control of your server, making it quite DANGEROUS. If you'd like to continue as root, please run this again, adding this flag: --allow-root If you'd like to run it as the user that this site is under, you can run the following to become the respective user: sudo -u USER -i -- wp[root@vccw vagrant]#
じゃrootになってアップデートしようとするとまたまた怒られました。「sudo -u USER -i — wp
[root@vccw vagrant]# wp cli update --allow-root You have version 0.22.0. Would you like to update to 0.23.0? [y/n] y Downloading from https://github.com/wp-cli/wp-cli/releases /download/v0.23.0/wp-cli-0.23.0.phar... New version works. Proceeding to replace. Success: Updated WP-CLI to 0.23.0 [root@vccw vagrant]#
rootになってオプション –allow-root をつけた「wp cli update –allow-root」で実行!これで無事アップデートできました。
更新後のバージョン確認
一般ユーザに戻してバージョン確認します。
[vagrant@vccw ~]$ wp cli version WP-CLI 0.23.0 [vagrant@vccw ~]$
0.23.0 にアップデートされていることを確認できました。