DEV Community

Kaspars Dambis
Kaspars Dambis

Posted on Originally published at kaspars.net on

Laravel Homestead for WordPress Theme and Plugin Development

Turns out Laravel Homestead is almost exactly the development environment I was looking for — it can be added as a Composer dependancy to any PHP project and configured using a simple Yaml file. The host machine needs only Vagrant and VirtualBox.

tl;dr: See this pull request for how I added Homestead to the Widget Context plugin.

How it Works

First, we add a very minimal Vagrantfile to the project root which reads the Homestead’s configuration from Homestead.yaml (could be named anything) and triggers the provisioning logic in scripts/homestead.rb using the supplied configuration.

We install WordPress a development dependancy in package.json and configured it from the same Vagrantfile using an inline shell script (and WP-CLI which comes bundled with Homestead):

config.vm.provision "shell",
    inline: "wp config create",
    privileged: false

and use a dedicated wp-cli.yaml which defines the database access parameters and credentials:

path: /home/vagrant/code

config create:
  dbname: homestead
  dbuser: homestead
  dbpass: secret

which are used as defaults during wp config create.

Note that wp-cli.yaml lives within our theme directory so we specify the WP_CLI_CONFIG_PATH environment variable in Homestead.yaml which points to wp-cli.yaml inside the virtual environment.

Notes

Laravel Homestead runs the provision scripts as root inside the virtual machine so the regular non-privileged vagrant user can’t write to disk which prevents us from downloading and setting up WordPress from within the virtual environment. This can probably be adjusted with a few additional lines of configuration in Homestead.yaml.

Top comments (0)