Setup WordPress development environment with Homestead

When we are working on WordPress that could be a theme or plugin development, the very first step is to set up a local development environment on your machine that could be Windows, Linux or MacOS.

It’s a very complicated part of setting up local WordPress development environment on various platforms Windows, Linux or MacOS. On Windows you need to set up WAMP software but if you are checking or developing emails related work then its a big pain for you. Or if you are using Linux or MacOS then you also need to proficient on both OS.

So without focusing on the development part, we need to dig the software issues as well.

Setting up Local Development Environment

Installing Vagrant

Vagrant provides a simple, elegant way to manage Virtual Machine. To set up Vagrant you need to install Virtual Box Machine as well. Both are free to use on any Operating System that you are using. After installing Virtual Box and Vagrant you need to run the following command vagrant box add laravel/homestead

Setting up Homestead

We are using Laravel Homestead package to setup WordPress development environment because it comes up with various software that we need for the development environment. You can easily switch to the various PHP version including the latest php 7.2, which is by default comes with. You can switch to various server Nginx or Apache. And many more.

Set up WordPress environment

We need to install the latest version of WordPress from site. After downloading open the working directory and run composer through terminal / command prompt with the following command composer require laravel/homestead --dev and if you are using Mac/Linux run php vendor/bin/homestead make or vendor\\bin\\homestead make for windows. This command generates a file Homestead.yaml, this file holds all the configuration related to your development environment.

Take a look on the above image and consider the folders section of the YAML file, map: /PATH/WORKING_DIRECTORY and sites section hold the URL that is used wp.local to locate on the browser.

Setting up hosts

After completing the Homestead.yaml configuration, you need to add an entry to your hosts file with the IP and the URL

Start Vagrant

Now everything is set up and you need to run the vagrant by commandvagrant up. After successfully compilation you need to locate the URL wp.local or whatever you set up on the Homestead.yaml file. For the database, there is default username/password that is homestead/secret respectively. The default database name is homestead that you can change on Homestead.yaml file and the host is not the localhost for the vagrant setup. The hostname is located on your Homestead.yaml file on the very bottom.

Please share your reviews on the below comment section.