3
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

アレな人でも使える 使い捨てWP環境を整える

Last updated at Posted at 2016-10-02

Docker とか Vagrant はエラー対応で詰むので、責任持たなきゃいけないケースでは余りオススメしたくない

Xampp や MAMP もエラー対応が面倒。よくわかんない環境になりガチ。

「困ったら再インストールしろ!」で投げられるお手軽環境が欲しいとき向けのCLIベースWordPress 環境構築を。

設計方針

  • wp cli でなんとかする。
  • WordPress 本体は core download で

wp コマンド

多分グローバルに入ってない人もいる & グローバルのバージョン管理面倒、なので、composer 経由で入れてもらう。

composerは入っていない人もいるので、Makefile なりを作って適宜引っ張ってこれるようにしておいてあげる。

composer:
	curl -sS https://getcomposer.org/installer | php

以下のコマンドでWordPress本体を引っ張ってきてconfigファイルの設定まで整えられる。

$ vendor/bin/wp core download
$ vendor/bin/wp core config

プラグイン

plugin install コマンドでプラグインの導入は可能。プラグインのファイル一式は事前にもっていてもいいが、
activate だけはしないと行けないので注意。

$ vendor/bin/wp plugin install contact-form-7 --activate

テーマ

テーマはおそらくいちばん手の入るところなので、composerで導入できるように。
composer installer を使えばローカルに配置したWordPress テーマをテーマフォルダに自動配置出来る。

/themes/mytheme/
/www/wp-content/
/www/wp-incluedes/
/www/wp-admin/

みたいなフォルダ構成の場合、/themes/mytheme/composer.jsonに以下の様な内容を追記。
name は任意の構成で良い。

{
    "name": "vedorname/mytheme",
    "type":"wordpress-theme",
    "authors": [
        {
            "name": "mikakane",
            "email": "mikakane2@gmail.com"
        }
    ],
    "require": {}
}

あとは親のcomposer.json で次のような記述を入れれば composer installで全てはよしなに進む。

    "repositories":[
        {
            "type":"path",
            "url": "./themes/mytheme/"
        }
    ],
    "require": {
        "composer/installers": "^1.2",
        "vendorname/mytheme": "dev-master",
        ...
    },
    "extra": {
        "installer-paths": {
            "wordpress/wp-content/themes/{$name}": ["type:wordpress-theme"]
        }
    }

テーマの有効化には theme activate コマンドが有効

$ vendor/bin/wp theme activate {theme_name}

データ

インポートツールを使ってファイル読み込み。
WordPress Importerが必要になるのでプラグインで以下を導入できるように。

vendor/bin/wp plugin install wordpress-importer --activate

その他

色々と細かい設定とかもあるのでその辺も極力コマンドで済ませたい。

パーマリンクの設定

$ vendor/bin/wp rewrite structure '/%category%/%post_id%/'

デフォルト投稿の削除

$ vendor/bin/wp post delete 1

タクソノミーの再集計(インポート後のエラーとかに)

$ vendor/bin/wp term recount {taxonomy_name}
3
4
1

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
3
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?