DEV Community

Kaspars Dambis
Kaspars Dambis

Posted on • Originally published at kaspars.net on

1 2

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.

AWS Q Developer image

Your AI Code Assistant

Generate and update README files, create data-flow diagrams, and keep your project fully documented. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Get started free in your IDE

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →