WordPress | WP-CLI をインストールする

WordPress を cli で操作するために、WP-CLI をインストールする。

インストール

1
2
3
4
5
6
7
8
$ sudo curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 5437k 100 5437k 0 0 7221k 0 --:--:-- --:--:-- --:--:-- 7221k
$ sudo chmod +x wp-cli.phar
$ sudo mv wp-cli.phar /usr/local/bin/wp
$ wp --version
WP-CLI 2.4.0

確認

1
2
3
4
5
6
7
8
9
10
11
12
13
$ wp --info
OS: Linux 4.19.128-microsoft-standard #1 SMP Tue Jun 23 12:58:10 UTC 2020 x86_64
Shell: /bin/bash
PHP binary: /usr/bin/php7.0
PHP version: 7.0.33-0ubuntu0.16.04.16
php.ini used: /etc/php/7.0/cli/php.ini
WP-CLI root dir: phar://wp-cli.phar/vendor/wp-cli/wp-cli
WP-CLI vendor dir: phar://wp-cli.phar/vendor
WP_CLI phar path: /mnt/c/Users/y.ken
WP-CLI packages dir:
WP-CLI global config:
WP-CLI project config:
WP-CLI version: 2.4.0

実行例

wp-config.phpの設定値を取得する †

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# sudo -u foo -i -- wp config get --path=/var/www/html
+------------------+------------------------------------------+----------+
| name | value | type |
+------------------+------------------------------------------+----------+
| table_prefix | wp_ | variable |
| DB_NAME | wordpress | constant |
| DB_USER | wordpress | constant |
| DB_PASSWORD | wordpress | constant |
| DB_HOST | db:3306 | constant |
| DB_CHARSET | utf8 | constant |
| DB_COLLATE | | constant |
| AUTH_KEY | db744531750667061d4612ab9f508451xxxxxxxx | constant |
| SECURE_AUTH_KEY | 3f82e5a52609dcd17a8b13e345e86fc2xxxxxxxx | constant |
| LOGGED_IN_KEY | ee177b6ed5dd2dc6a1197dbff37b11acxxxxxxxx | constant |
| NONCE_KEY | 71eacdcec6fec70207e023e8ff3166d1xxxxxxxx | constant |
| AUTH_SALT | 7a1956b2c4416ee1b74a6c28a8875fe0xxxxxxxx | constant |
| SECURE_AUTH_SALT | 91861f5fcc2586828f04240647d83ea4xxxxxxxx | constant |
| LOGGED_IN_SALT | 7e02e561fffe75857285cf2513b3c04fxxxxxxxx | constant |
| NONCE_SALT | de2b0d3310dabd291b3bfd82e6128712xxxxxxxx | constant |
| WP_DEBUG | 1 | constant |
+------------------+------------------------------------------+----------+