wordpress maintenance by threenine.co.uk

Setting up a local WordPress Development Environment

Over the years we have explored and used a number of different approaches to setting up a WordPress development environment. These have included 

And a whole host of other solutions, some we’ve cobbled together using different ideas and solutions.

 

We’ve been trying to get to the perfect solution to enable the least amount of friction from a developers perspective.

 

When developing WordPress websites, it is preferable to set up a local environment with a local web server, a database tool, Debugger and a number of other handy tools.

 

The above approaches work fine if you only work on a few projects. However, when they multiply, problems occur involving maintaining multiple environments, because each client may have a different configuration.

 

Fortunately, there is Vagrant which is a tool for creating and configuring virtual environments. It provides an easy way to set up a local development environment with a few commands, and you can replicate a complete setup as many times as you want, with ease and without the hassle of installing everything locally.

 

Vagrant works with virtual environments, you need virtual machine software to run Vagrant.

 

For our purposes, we will use the Open Source Virtualbox.

What is Varying Vagrant Vagrants

A Web development Agency, by the name of called 10up, who primarily work with WordPress, started to become overwhelmed due to the repetitive robotics task of configuring the WordPress development environment each time when a new project came on board. They innovated an idea to create a universal configuration for local WordPress development.

 

They created a Vagrant configuration especially for WordPress that includes all the necessary software and other dependencies required to run WordPress efficiently in a completely isolated environment. In 2014 they made it an open-source and community-driven project, VVV is MIT licensed.

What is installed with VVV?

How to Install Virtual box using the Terminal Ubuntu 20.04

VirtualBox is an open source cross-platform virtualisation application that allows you to run just about any operating system on your existing operating system without the need to create additional partitions.

Essentially it creates a virtual machine or virtual machines as you can create as many as your resources will allow, each one with either the same or a different OS

To install VirtualBox on Ubuntu open the terminal window.

 sudo add-apt-repository multiverse && sudo apt-get update
  sudo apt install virtualbox -y 

How to install vagrant on ubuntu

Vagrant is a wrapper for virtualisation tools like VirtualBox.  It enables set up and management of virtual machines through a command line interface.

 

Using Vagrant it is easy to create portable reproducible development environments that can be shared by each member of a development team. 

 

Using Vagrant is easy. You create a Vagrantfile which defines your base box containing the OS you will be using in your repository root. The file includes the IP address, the shared project folder, and other information; then you just run vagrant up

 

To install vagrant on Ubuntu still requires downloading form vagrant downloads page. Typically the download will be a zip file which contains the vagrant executable. Extract this file and move it to the /usr/bin

 

We can simply check the vagrant version installed in the terminal window by using the vagrant -v

cd Downloads\nunzip vagrant_2.2.9_linux_amd64.zip  #This will be depending on your version number
sudo mv vagrant /usr/bin 

We can simply check the vagrant version installed in the terminal window by using the vagrant -v

Once the vagrant is installed, we need to install an additional vagrant-hostsupdater plugin to enable adding an entries to your /etc/hosts file on the host system.

 

vagrant plugin install vagrant-hostsupdater 

How to Configure Vagrant Local

We are now ready to clone the VaryingVagrantsVagrant environment. Assuming you have Git installed and already configured to make use of SSH keys, we can simply clone the repository.

git clone -b stable git://github.com/Varying-Vagrant-Vagrants/VVV.git ~/vagrant 

Review Vagrant-local folder

In vagrant-local/config there is a file called default-config.yml contains the configuration regarding the first provisioning. All WordPress sites and their configuration can be managed within this file.

It is a good idea to create a custom configuration file based on the default configuration file before we make any changes to the configuration. To create a custom configuration file you need run command vagrant status inside the vagrant-local folder. And it will create config/config.yml copying the content of the default-config.yml file. Now you can make changes to the custom configuration file i.e. config.yml

vagrant-local

For the purpose of this quick quide, we are just going to focus on making use of the default options provided in Varying Vagrant Vagrants configuration file, in a future deep-dive article we will provide further detail on how to configure and use other functionalities provided.

Once the repository has completed cloning, we can change into the vagrant-local folder and start the vagrant environments.

This step may take a little time to complete.

VVV Commands

Most interactions are carried out through the command line interface. Commands begin with vagrant which is followed by a sub-command.

vagrant up – starts the VVV virtual machine. It sets up the hosts file with local domain names; updates Word Press local versions; runs custom init scripts.

vagrant halt – shuts down VVV virtual machine gracefully and frees up resources when VVV isn’t being used.

vagrant suspend – suspends the virtual machine in a precise point of time state.

vagrant resume – resumes the suspended virtual machine.

vagrant provision – runs configured provisioners to install software automatically and change configurations. Enables you to modify provisioning scripts and check that you get the required result.

vagrant ssh – connects to VVV via SSH (secure shell) allowing commands to be run inside the virtual machine.

vagrant destroy – stops the virtual machine and removes all resources created during machine creation; leaves your computer in a clean state.

Using VaryingVagrantVagrants

The default configuration of the VVV out the box, is configured to provide 2 default WordPress websites and default tools one would use to develop, maintain and manage WordPresss websites.

To see this you can visit the default site now available on http://vvv.test

You will notice that there are 2 WordPress websites available :

You are able to login into the Administration website /wp-admin using the the default credentials of user: admin password: password , in both

 

Follow Me