Set up Wordpress right

Joachim Eckerlin
3 min readJul 31, 2022
Photo by Fikret tozak on Unsplash

Wordpress can be really hard to work with. Once it outgrows the basic portfolio page type of site or once you have some real business customers on the site, updates on production become a nerve wrecking experience, since downtimes are bound to happen from time to time.

So you need a setup, that allows you to run the site locally in a development environment in a way that closely resembles production, you want a staging system to preview you’re changes before they get public and can be seen by everyone and you probably want some way to update your plugins and themes and lock them to a certain version to test the updates locally. So let’s see how to achieve such a setup.

First things first: at this point you should definitely have a vcs (version control system) like git to track the changes you make to the code.

This topic is too big to fit everything in one article so I will make it a series:

  • Part 1 (this one): How to setup Wordpress with ddev and composer
  • Part 2: How to install plugins and themes
  • Part 3: How to deploy your Wordpress via GitHub Actions and Deployer

Setup local development environment with DDEV

For our local development environment I suggest using ddev. To setup a new Wordpress project, you just run the following command and you got yourself a new basic setup for a new wordpress project.

ddev config --project-type=wordpress --docroot=web --create-docroot
ddev start

It will setup php, database and webserver for you, provide you with a local domain, including SSL and with some handy tools like phpmyadmin to have a better look at your database. For more information on how to setup and use ddev consider the official documentation: https://ddev.readthedocs.io/en/latest/users/quickstart/

DDEV modifies your hosts file to give you a nice local URL like your-project-name.ddev.site so you will probably be prompted to type in your sudo password while running those commands.

Setup Wordpress

With our development environment in place, we can now start to actually set up Wordpress. You can chose the classic way of downloading the source for everything and checking it into your git repository. While there is nothing inherently bad with that approach, it produces a lot of noise in your versioning and if you work as a team on the project and to an update the PR will be extremly big, since all the core or plugin files are changed. So I prefer to use the package manager composer to manage the installed wordpress version, plugins and themes. To get started, just run ddev composer create roots/bedrock , this will create a fresh and empty Wordpress installation for you. In your composer.lock file you can see the exact versions of every packages, that is installed and if you want to update your Wordpress just run ddev composer update roots/wordpress . That way updating wordpress only changes one file (composer.lock ).

Edit the created .env file to start with the following lines:

DB_NAME='db'
DB_USER='db'
DB_PASSWORD='db'
DB_HOST='db'
WP_ENV='development'
WP_HOME=${DDEV_PRIMARY_URL}
WP_SITEURL=${WP_HOME}/wp

To finish the installation run ddev launch to open the newly installed wordpress and follow the steps to set all the remaining settings.

Now you have a running wordpress installation and can start writing posts. I will cover the installation of plugins and themes in a part 2 of this article series.

I created a Demo Repository for you to see how everything should look like: https://github.com/TheJotob/wordpress-ddev-composer

--

--

Joachim Eckerlin

Senior Software engineer at pryntad. Cloud and DevOps enthusiast. Budgeting nerd.