LoginSignup
22
15

More than 5 years have passed since last update.

さくらのレンタルサーバー(スタンダード)にWP-CLIをインストールする(完全版)

Last updated at Posted at 2017-10-02

さくらのレンタルサーバーにWP-CLIをインストールする方法を紹介します。

これについてはすでにいろいろなところで書かれていますが、設定ファイルやコマンド補完などについても紹介されているものを見つけられなかったので書くことにしました。

WP-CLIをインストール

今回は、WP-CLIのnightlyバージョンをインストールしましょう。

以下のコマンドをコピペして実行してください。

mkdir -p $HOME/bin && curl -L https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli-nightly.phar -o $HOME/bin/wp && chmod 755 $HOME/bin/wp

以上で wp コマンドが使えるようになったはず。

$ wp --info
PHP binary: /usr/local/bin/php-wrapper
PHP version:    7.1.9
php.ini used:   /usr/local/php/7.1/etc/php.ini
WP-CLI root dir:    phar://wp-cli.phar
WP-CLI vendor dir:  phar://wp-cli.phar/vendor
WP_CLI phar path:   /home/xxxx
WP-CLI packages dir:    
WP-CLI global config:   /home/xxxx/.wp-cli/config.yml
WP-CLI project config:  
WP-CLI version: 1.4.0-alpha-34bfe03

設定ファイルを作成

今回はとりあえず空の設定ファイルを作ります。

$ mkdir -p $HOME/.wp-cli && touch ~/.wp-cli/config.yml

設定ファイルは使いこなすと便利なので、興味がある人は以下をご覧になってください。

シェルを bash に変更

これは好みですが、WP-CLIは bash をベースにテストされているので、さくらのレンタルサーバーのデフォルトの csh ではところどころで微妙に残念です。

$ chsh -s /usr/local/bin/bash

もし、bash に変更しない人は以下は関係ありません。

WP-CLIのコマンド補完を有効化する

まずコマンド補完に必要なファイルを設置。

$ curl -L https://raw.githubusercontent.com/wp-cli/wp-cli/master/utils/wp-completion.bash -o ~/.wp-cli/wp-completion.bash

次に以下を ~/.bash_profile に追加。~/.bash_profileがなければ作ってください。

source $HOME/.wp-cli/wp-completion.bash

以上で完了です。一度ログアウトしてログインし直すと以下のようにタブキーでコマンドが補完されます。

$ wp core 
check-update        is-installed        update              
download            multisite-convert   update-db           
install             multisite-install   version 
22
15
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
22
15