WP CLI

wp-cli/doctor-commandをつかってみた

wp-cli/doctor-commandが気になったので、自分のサーバーに入れてみました。 環境 ___ _ __ / _ | __ _ (_)_ _ ___ / /____ / __ |/ ‘ \/ / ‘ \/ _ […]

広告ここから
広告ここまで

wp-cli/doctor-commandが気になったので、自分のサーバーに入れてみました。

環境

      ___         _            __
     / _ | __ _  (_)_ _  ___  / /____
    / __ |/  ' \/ /  ' \/ _ \/ __/ _ \
   /_/ |_/_/_/_/_/_/_/_/\___/\__/\___/

https://aws.amazon.com/amazon-linux-ami/2017.03-release-notes/

 Nginx 1.13.5, PHP 7.0.24, Percona MySQL 5.6.37, WP-CLI 1.3.0

 amimoto     https://www.amimoto-ami.com/
 digitalcube https://en.digitalcube.jp/

インストール

READMEを参考にコマンドをインストールします。

$ wp package install git@github.com:wp-cli/doctor-command.git
Installing package wp-cli/doctor-command (dev-master)
Updating /home/ec2-user/.wp-cli/packages/composer.json to require the package...
Registering git@github.com:wp-cli/doctor-command.git as a VCS repository...
Using Composer to install the package...
---
Loading composer repositories with package information
Updating dependencies
Resolving dependencies through SAT
Dependency resolution completed in 0.096 seconds
Analyzed 4547 packages to resolve dependencies
Analyzed 189746 rules to resolve dependencies
Package operations: 1 install, 0 updates, 0 removals
Installs: wp-cli/doctor-command:dev-master 0049d15
 - Installing wp-cli/doctor-command (dev-master 0049d15)
Writing lock file
Generating autoload files
---
Success: Package installed

確認

パッケージコマンドはwp package listで一覧表示ができます。

$ wp package list
+-----------------------+------------------+------------+--------+----------------+
| name                  | authors          | version    | update | update_version |
+-----------------------+------------------+------------+--------+----------------+
| wp-cli/doctor-command | Daniel Bachhuber | dev-master | none   |                |
+-----------------------+------------------+------------+--------+----------------+

追加できていますね。

使ってみる

とりあえずwp help doctorで何ができるかみてみます。

$ wp help doctor
NAME

  wp doctor

DESCRIPTION

  Diagnose what ails WordPress.

SYNOPSIS

  wp doctor <command>

SUBCOMMANDS

  check      Run a series of checks against WordPress to diagnose issues.
  list       List all available checks to run.

listで何がチェックできるかのリストが見れて、checkで実際にチェックができる様子です。

wp doctor list

とりあえず一覧表示してみます。
アップデートの確認や改ざんチェックなど、かなりいろいろなチェックができます。

$ wp doctor list
+----------------------------+--------------------------------------------------------------------------------+
| name                       | description                                                                    |
+----------------------------+--------------------------------------------------------------------------------+
| autoload-options-size      | Warns when autoloaded options size exceeds threshold of 900 kb.                |
| constant-savequeries-falsy | Confirms expected state of the SAVEQUERIES constant.                           |
| constant-wp-debug-falsy    | Confirms expected state of the WP_DEBUG constant.                              |
| core-update                | Errors when new WordPress minor release is available; warns for major release. |
| core-verify-checksums      | Verifies WordPress files against published checksums; errors on failure.       |
| cron-count                 | Errors when there's an excess of 50 total cron jobs registered.                |
| cron-duplicates            | Errors when there's an excess of 10 duplicate cron jobs registered.            |
| file-eval                  | Checks files on the filesystem for regex pattern `eval\(.*base64_decode\(.*`.  |
| option-blog-public         | Confirms the expected value of the 'blog_public' option.                       |
| plugin-active-count        | Warns when there are greater than 80 plugins activated.                        |
| plugin-deactivated         | Warns when greater than 40% of plugins are deactivated.                        |
| plugin-update              | Warns when there are plugin updates available.                                 |
| theme-update               | Warns when there are theme updates available.                                  |
| php-in-upload              | Warns when a PHP file is present in the Uploads folder.                        |
| language-update            | Warns when there are language updates available.                               |
+----------------------------+--------------------------------------------------------------------------------+

wp doctor check

ということで早速走らせてみます。
wp doctor checkの後ろにチェック項目を指定すると、その項目をチェックしてくれます。

コアのバージョンが最新版かを確認するwp doctor check core-update

wp doctor check core-updateを実行することで、WordPressのバージョンが最新版か確認できます。

$ wp doctor check core-update
+-------------+---------+-------------------------------------+
| name        | status  | message                             |
+-------------+---------+-------------------------------------+
| core-update | success | WordPress is at the latest version. |
+-------------+---------+-------------------------------------+

全てのテストを実行する

--allをつけることで、すべてのテストを一気に実行できます。

$ wp doctor check --all
Running checks  100% [==================================================================================================================] 0:03 / 0:02
+----------------------------+---------+--------------------------------------------------------------------+
| name                       | status  | message                                                            |
+----------------------------+---------+--------------------------------------------------------------------+
| core-verify-checksums      | success | WordPress verifies against its checksums.                          |
| file-eval                  | success | All 'php' files passed check for 'eval\(.*base64_decode\(.*'.      |
| autoload-options-size      | success | Autoloaded options size (91.43kb) is less than threshold (900kb).  |
| constant-savequeries-falsy | success | Constant 'SAVEQUERIES' is undefined.                               |
| constant-wp-debug-falsy    | success | Constant 'WP_DEBUG' is defined falsy.                              |
| core-update                | success | WordPress is at the latest version.                                |
| cron-count                 | success | Total number of cron jobs is within normal operating expectations. |
| cron-duplicates            | success | All cron job counts are within normal operating expectations.      |
| option-blog-public         | success | Site is public as expected.                                        |
| plugin-active-count        | success | Number of active plugins (6) is less than threshold (80).          |
| plugin-deactivated         | warning | Greater than 40 percent of plugins are deactivated.                |
| plugin-update              | success | Plugins are up to date.                                            |
| theme-update               | success | Themes are up to date.                                             |
| php-in-upload              | success | No PHP files found in the Uploads folder.                          |
| language-update            | warning | 1 language has an update available.                                |
+----------------------------+---------+--------------------------------------------------------------------+

plugin-deactivatedlanguage-updateが指摘されました。

language-updatewp core language updateを実行することで解決できます。

$ wp core language update
$ wp doctor check language-update
+-----------------+---------+---------------------------+
| name            | status  | message                   |
+-----------------+---------+---------------------------+
| language-update | success | Languages are up to date. |
+-----------------+---------+---------------------------+

plugin-deactivatedについては、「使ってないプラグイン整理しろ」ということなので整理しましょう。

Tips

出力の変更

WP-CLIコマンドの出力は基本的に--format=jsonでJSON出力できることが多いです。

$ wp doctor check core-update --format=json  | jq .
[
  {
    "name": "core-update",
    "status": "success",
    "message": "WordPress is at the latest version."
  }
]

cronで監視することもできそうですし、AMIMOTO AMIのSSLドメインとかWordPress情報を収集するEC2 Systems Manger Documentを作ってみたの記事にあるように、EC2 Systems Managerと組み合わせることで外部からのモニタリングなども簡単にできそうです。

ブックマークや限定記事(予定)など

WP Kyotoサポーター募集中

WordPressやフロントエンドアプリのホスティング、Algolia・AWSなどのサービス利用料を支援する「WP Kyotoサポーター」を募集しています。
月額または年額の有料プランを契約すると、ブックマーク機能などのサポーター限定機能がご利用いただけます。

14日間のトライアルも用意しておりますので、「このサイトよく見るな」という方はぜひご検討ください。

広告ここから
広告ここまで

Related Category posts