WordPlate
とは composer によるWordPressスタックの構築をサポートし、
DockerやVMを使わず(もちろん一緒に使っても良いんですが)ローカルPC上(macとかwindows)
すぐにテーマやプラグインを開発するためのコードベース。
Webサーバに こだわりがなければ、PHPの組み込み済みのものを使うこともできます。
DBは事前にインストールしておく必要があります。
用途としては、テーマやプラグインを1から作るときに便利かと思います。
Laravel Mixとの統合ができるようになっているのも利点の一つです。
フロント側のモジュールバンドラには webpack
を使っています。
スタック(環境変数、テーマ、プラグイン、ベンダーライブラリなどなど)の管理は composer.json に集約されているみたいです。
例えばWordPressプラグイン を追加したい場合は:
1 2 |
$ composer require wpackagist-plugin/nanka |
とすることで、インストールすることができます。
それでは、WordPlateでWordPressを構築し、ログインするところまでやってみます。
composerから利用することができるテーマやプラグインは以下サイトで見つけることができます:
WordPress Packagist: Manage your plugins and themes with Composer
Contents
試した環境
- macOS High Sierra
必要なもの
- PHP >= 7.1.3
- Mbstring PHP Extension
- composer
- mariadb
Laravel Mix を使ってアセットパイプラインを構築したい場合は、
別途 Node.js
が必要になります。
それと mysql(=mariadb) をインストールしてない場合こちらを参考:
macOSにmariaDBをインストールして起動したり | wpken.net
composerでプロジェクトを作成する
1 2 |
$ composer create-project wordplate/wordplate mysite1 |
これで mysite1
というフォルダにwordplateが展開されます。
実行結果
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
Installing wordplate/wordplate (6.3.1) - Installing wordplate/wordplate (6.3.1): Downloading (100%) Created project in /Users/yokada/Dropbox/wordpress/wordplate-dev/mysite1 > @php -r "file_exists('.env') || copy('.env.example', '.env');" Loading composer repositories with package information Updating dependencies (including require-dev) Package operations: 20 installs, 0 updates, 0 removals - Installing composer/installers (v1.6.0): Downloading (100%) - Installing johnpbloch/wordpress-core-installer (1.0.2): Downloading (100%) - Installing vlucas/phpdotenv (v2.5.1): Downloading (100%) - Installing symfony/polyfill-php72 (v1.10.0): Downloading (100%) - Installing symfony/polyfill-mbstring (v1.10.0): Downloading (100%) - Installing symfony/var-dumper (v4.1.7): Downloading (100%) - Installing symfony/routing (v4.1.7): Downloading (100%) - Installing symfony/http-foundation (v4.1.7): Downloading (100%) - Installing roots/wp-password-bcrypt (1.0.0): Downloading (100%) - Installing johnpbloch/wordpress-core (4.9.8): Downloading (100%) - Installing johnpbloch/wordpress (4.9.8): Downloading (100%) - Installing symfony/translation (v4.1.7): Downloading (100%) - Installing nesbot/carbon (1.35.1): Downloading (100%) - Installing psr/simple-cache (1.0.1): Downloading (100%) - Installing psr/container (1.0.0): Downloading (100%) - Installing illuminate/contracts (v5.7.11): Downloading (100%) - Installing doctrine/inflector (v1.3.0): Downloading (100%) - Installing illuminate/support (v5.7.11): Downloading (100%) - Installing wordplate/framework (6.3.1): Downloading (100%) - Installing wordplate/plate (4.0.3): Downloading (100%) symfony/var-dumper suggests installing ext-intl (To show region name in time zone dump) symfony/var-dumper suggests installing symfony/console (To use the ServerDumpCommand and/or the bin/var-dump-server script) symfony/routing suggests installing doctrine/annotations (For using the annotation loader) symfony/routing suggests installing symfony/config (For using the all-in-one router or any loader) symfony/routing suggests installing symfony/dependency-injection (For loading routes from a service) symfony/routing suggests installing symfony/expression-language (For using expression matching) symfony/routing suggests installing symfony/yaml (For using the YAML loader) symfony/translation suggests installing symfony/config symfony/translation suggests installing symfony/yaml symfony/translation suggests installing psr/log-implementation (To use logging capability in translator) nesbot/carbon suggests installing friendsofphp/php-cs-fixer (Needed for the `composer phpcs` command. Allow to automatically fix code style.) nesbot/carbon suggests installing phpstan/phpstan (Needed for the `composer phpstan` command. Allow to detect potential errors.) illuminate/support suggests installing illuminate/filesystem (Required to use the composer class (5.7.*).) illuminate/support suggests installing moontoast/math (Required to use ordered UUIDs (^1.1).) illuminate/support suggests installing ramsey/uuid (Required to use Str::uuid() (^3.7).) illuminate/support suggests installing symfony/process (Required to use the composer class (^4.1).) Writing lock file Generating optimized autoload files |
一発目は、少し時間がかかるかもです。2回目からは早いです。
できたファイル
1 2 3 4 5 6 7 8 9 10 11 12 |
$ ls mysite1 LICENSE README.md composer.json composer.lock package.json public resources vendor webpack.mix.js wp-cli.yml |
設定
saltを mysite1/.env に保存する
以下URLにアクセスして 文字列 をコピーします:
– http://wordplate.github.io/salt/
mysite1/.env
ファイルの下の方に salt を貼り付けます。
↓貼り付けたところ:
DBを作る そして .env にDB情報を書き込む
1 2 3 |
$ mysql -uroot > create database `mysite1`; |
mysite1/.env
1 2 3 4 5 |
DB_HOST=127.0.0.1 DB_NAME=mysite1 DB_USER=root DB_PASSWORD= |
↑適宜読み替え
DBを起動しておく
1 2 |
$ mysql.server start |
PHP組み込み済みのWebサーバで動かしてみる
1 2 |
$ php -S localhost:8000 -t public |
そして http://localhost:8000 にアクセスし以下のようにWordPressのインストール画面が表示されればOK:
あとは、いつものようにインストールをすすめる
インストール完了したらログインしてみる:
ログインURL:
http://localhost:8000/wordpress/wp-login.php
PHP組み込みWebサーバが落ちることがある
1 2 3 4 5 |
[Fri Nov 16 03:51:56 2018] ::1:50633 [200]: /wordpress/wp-includes/js/underscore.min.js?ver=1.8.3 [Fri Nov 16 03:51:59 2018] ::1:50635 [200]: /wordpress/wp-cron.php?doing_wp_cron=1542307915.9273099899291992187500 [1] 16803 segmentation fault php -S localhost:8000 -t public No notifier program found. |
php -S ...
で立ち上げ直して再度試してみよう。
ログインできた
開発用のURLを変更したい場合
WP_HOME
、WP_SITEURL
、WP_CONTENT_URL
を .evn に追記します.
1 2 3 4 |
WP_HOME=https://mysite1.test WP_SITEURL=https://mysite1.test WP_CONTENT_URL=https://mysite1.test |
WordPresのバージョンを変更したい
wordplate/composer.json
で バージョンを書き換えて composer update
します。
wp-cliを入れる
1 2 3 |
$ composer require wp-cli/wp-cli $ composer require wp-cli/wp-cli-bundle |
vendor/bin/
に wp
コマンドがインストールされる。
そしてcomposer.json の require
には以下の2行が追加されているはず。
1 2 3 4 5 6 7 8 |
... "require": { ... "wp-cli/wp-cli": "^2.4", "wp-cli/wp-cli-bundle": "^2.4" }, ... |
コマンドでWordPressをインストール&セットアップ
wp-cli
がインストールされている前提。
1 2 |
$ vendor/bin/wp core install --title=bulk_convert_images --admin_user=admin --admin_password=admin --admin_email=test@example.com --url=${WP_CONTENT_URL} --path=public/wordpress |
テーマを作りたい
… wip …
プラグインを作りたい
… wip …
Laravel Mix インテグレーション
… wip …
No comment yet, add your voice below!