WordPress Local Development Using The Devilbox
If you prefer to develop web apps on your local machine, then you have probably tried out a few local LAMP development stacks such MAMP, WAMP, or Local by Flywheel, to name a few of the most popular. You may also have put yourself through the torture of taking the DIY approach by attempting to build your own stack on Docker.
While these instruments of Satan make setup easy, they mostly limit you to a conventional Apache, MySQL and PHP stack and can often be slow and resource hungry. For instance, MAMP Pro which I've used for several years, allows you to switch to Nginx, change PHP versions, and generally provides a little more flexibility than the others, but personally, I find that it runs like treacle after 30-minutes or so and needs to be restarted. The free version of Local by Flywheel offers a good alternative, and the more recent Docker-based DevKinsta is simple to set up and I've found that it runs fast and smooth on my elderly 2015 MacBook Pro.
However, I wanted a solution that I could set up to mimic my typical WordPress hosting configuration as closely as possible, and after many lockdown hours of searching the web, I came across The Devilbox (plus a few other strong contenders that I will review at a later date).
For now, let's focus on WordPress local development using The Devilbox.
The Devil Has All the Best Tunes
The Devilbox aims to provide you with a universal zero-configuration LAMP and MEAN development environment for any purpose which is setup in less than 5 minutes.
Its main intention is to support an unlimited number of projects for any framework or CMS, and to be portable across all major operating systems, as well as providing any available PHP version with whatever module you require.
That's how Cytopia, The Devilbox's German developers describe their product, and it's a fair and honest statement. And as far as my quest for local development Utopia goes, The Devilbox is the best I've found so far.
The official documentation is excellent, but I found myself jumping between pages too much while I was installing it for the first time. So, this article is intended as a quick-start guide for anyone who would like to install and try out The Devilbox for themselves. It is not intended as a full, in-depth review.
Let's get started.
Docker is a prerequiste for running The Devilbox. You have the choice of installing Docker Toolbox or Docker Desktop. Desktop is the preferred option and is what we will be using here.
Install The Devilbox
Next, create the directory in which you wish to install The Devilbox (let's call it 'your-devilbox-directory'), navigate into it in a terminal and run:
$ git clone https://github.com/cytopia/devilbox
Edit the .env file
Look in your cloned Devilbox git directory and find a file called env-example and copy it to a new file named .env.
$ cp env-example .env
**Note: **It may be possible to skip the UID and GID steps below if you're using the latest version of Docker Desktop for Mac, but it will do no harm to complete them anyway.
This new .env file stores all of the environment variables for Docker Compose and is used as the main configuration file for The . The excellent Devilbox documentation goes into the workings of the .env file in detailand I suggest you read through it at some point. For now, all we need to do in the .env file is change the values of NEW_UID and NEW_GID variables with our own IDs.
To obtain your UID:
$ id -u
To obtain your GID:
$ id -g
Make a note of these two values then open the .env file in your favourite editor. I'll be using Nano:
$ nano .env
Then set NEW_UID and NEW_GID to the values you obtained in the previous steps and save the .env file.
Now let's see if we've been successful...
- In your terminal, navigate to your Devilbox installation directory and start docker:
$ cd /your-devilbox-directory $ docker-compose up bind httpd php mysql
Note: the services arguments (httpd, php, mysql) are optional and you can omit them if you want to start all available services. The selection in the example will give us an Nginx server, running PHP and MySQL.
- You can check if the selected services have started using:
$ docker-compose ps
- You can now start the Devilbox Intranet in your browser at https://localhost which will give you some reassurance that Devilbox really is up-and-running.
Create a new project
- Using a terminal, navigate to the Devilbox installation directory:
$ cd /your-devilbox-directory
- Start the Devilbox's built-in shell to enter the PHP container:
Note: You can only enter the PHP container if it is actually running.
This will take you to /shared/httpd
- Create a new project folder:
$ mkdir project-name
Let your Mac's hosts file (/etc/hosts) know about your new site by adding the following line to it:
Note: By default, The Devilbox sets the top level domain extension (TLD) to .loc. You can change this in the .env file by editing the TLD_SUFFIX variable.
- Download WordPress to your project folder, and either:
Clone WordPress via Git:
$ git clone https://github.com/WordPress/WordPress wordpress.git
Or, download directly from WordPress:
$ curl -O https://wordpress.org/latest.zip $ unzip latest.zip $ mv wordpress project-name $ rm latest.zip
We now need to create a symlink from our htdocs folder to the WordPress installation. See here to learn why this is necessary.
$ ln -s wordpress/ htdocs
Now check that the directory structure looks like this:
$ tree -L 1 . ├── wordpress.git └── htdocs -> wordpress.git 2 directories, 0 files
- Create a database:
$ mysql -u root -h 127.0.0.1 -p -e 'CREATE DATABASE your_db_name;'
Note: Use the default MariaDB password = password
- Visit your project url in a browser and run the WordPress installation as normal.
That's it. You're done!
Better the Devil You Know?
You're done! That's all there is to WordPress local development using The DevilBox. Now go read the documentation.