DDEV WordPress Multisite Setup
Setting Up a Local WordPress Multisite with Subdirectories Using DDEV
Setting up a local WordPress multisite environment can be challenging, especially when dealing with subdirectory installs. In this guide, we'll walk through the process of setting up a full local multisite installation supporting subdirectories using DDEV, with a focus on Pantheon integration.
👉 This guide assumes that you already have a WordPress multisite project set up on live and are looking to create a local development environment for it.
If you need to set up a new WordPress multisite project, you can follow the WordPress Codex guide.
Prerequisites
DDEV installed on your local machine
Drush (Optional, for Pantheon integration), to get it, run
ddev composer require drush/drush
Ability to endure pain if things go wrong 😅 (believe me they will)
Let's get started!
Configure DDEV
Clone the Repository
First, clone your project repository to your local machine:
git clone [your-repo-url]
cd [your-project-directory]
Run the DDEV configuration command:
ddev config
and answer the prompts.
Modify DDEV Configuration
In the .ddev/config.yaml
file, change the webserver type to Apache:
webserver_type: apache-fpm
We are moving to good ole Apache because handling subdirectory installs are much easier in Apache with .htaccess
compared to Nginx or at least I did not have a good time with it when I was playing with nginx-site.conf
file auto-generated by DDEV 🤦♂️
Create .htaccess
File
Create a .htaccess
file in the root of your project and add it to .gitignore
. Paste the following content into the file:
I have directly copied the content of .htaccess
file from the WordPress MultiSite Network Administration docs for WordPress version 3.5 and higher.
⚠️ Important: Note line 7 in .htaccess
where it adds a trailing slash to the wp-admin. If we don’t do this, the subdirectories as well as their wp admin will not load!
Configure WordPress
Since we're using Pantheon, we'll use wp-config-local.php
instead of wp-config.php
:
Add
wp-config-ddev.php
to.gitignore
.Remove any database connection settings from
wp-config-local.php
.Add the following to the bottom of
wp-config-local.php
:
If we were not using pantheon wordpress_network upstream and the default wp-config.php
that comes with it, or if we were setting up the multisite from scratch, we would have added the following to the bottom of wp-config-local.php
(since the wp-config-ddv.php file is auto-generated by DDEV and we have less control over it):
⚠️ Important: Most of the time (if not all the time!) you would be experiencing login problems, such as the inability to log in due to the cookie issues. From here, you need to play with the cookie settings in wp-config-local.php
for example trying to set define( 'COOKIE_DOMAIN', 'your-local-ddev-site.ddev.site:447' );
which in most cases you would see the warning about the constant being already defined in wp-config.php
. Then simply set these in wp-config-local.php
:
Optional Pantheon Integration
If you don't need Pantheon integration, you can skip this section and move to the Pull Database and files section.
Follow the Pantheon integration guide for DDEV:
⚠️ Important: Make sure that you follow pantheon guide for Drush and the machine token otherwise none of this is going to work.
Pull Pantheon Data
Pull the database from Pantheon ( I am skipping files and only pulling the database because I am not interested in the files, but you can pull them as well if you want):
If you want to pull the files as well, you can run the following command:
Note: See the section below for an alternative method to pull the files.
Terminus
If you are using Terminus, you can use the following command to pull the database:
See the Terminus documentation for more information.
Database and files
Export the database from live site
Export your database with whatever tool that your hosting provider provides, or if you use a plugin like WP Migrate DB, you can use that as well.
Import Database
Import the database into your local environment:
DDEV has pretty straightforward documentation about this.
Files
Using the command line tools, sftp client, or any other method, copy the files from your live site to the wp-content/uploads directory in your local environment.
I usually use Bill Erickson's Media From Production to read media files from the live site and save myself a couple of GBs of storage. The plugin is a real gem!
Update URLs and Paths
After pulling the database from Pantheon, you need to update the URLs and paths to match your local environment. Use the wp search-replace
command:
Replace live-yoursite.pantheonsite.io
with your actual Pantheon live URL, and yoursite.ddev.site
with your local DDEV URL. Note that you may also need to specifically target the wp_options
table, wp_blogs
, and wp_sites
as well, otherwise, you may be seeing redirections from your local to the live site when you attempt to browse your network sites locally. So:
Important: Note the *
before wp_options
which means the options tables for all the sites in the network.
Create/Edit WordPress User
Create a new WordPress user:
Update the new WordPress user’s role:
Add Super Admin
Make your user a super admin, because otherwise you will not be able to access the network admin area:
Conclusion
By following these steps, you'll have a fully functional local WordPress multisite environment set up with DDEV, supporting subdirectory installs and integrated with Pantheon. This setup provides a robust development environment for working on WordPress multisite projects.
The wp search-replace
command is crucial for ensuring that your local site works correctly with the database pulled from the live version.