Setting up Wordpress Multisite using Docker and a custom port

CAUTION: This is not an ideal path I would use in Production. I would need to think very strongly before using it in Development too.

I am posting with the intention that it helps bring together some of the info and it does help someone in a pinch, or maybe even to work out a long-term solution.

There are a few tickets and posts out there noting that you can't run Wordpress Multisite on a non-standard port (80 or 443).

https://core.trac.wordpress.org/ticket/21077

https://core.trac.wordpress.org/ticket/42993

https://wordpress.stackexchange.com/questions/212978/multisite-network-port-num-issues

That said, here are my notes/steps towards adjusting it to get it working. It is completely outside the realm of what I would do in Production, but for testing in development where I can't use port 80, it works.

Initial setup

  1. Clone the docker-compose repo
  2. Set up Wordpress http://localhost:8000
  3. Enable Multisite in wp-config.php
define( 'WP_ALLOW_MULTISITE', true );
  1. Edit /etc/hosts and add a few entries for the sites you want to configure
172.99.0.9     wordpress1.localhost
172.99.0.9     wordpress2.localhost

Adjustments

If you go to Tools => Network Setup now, you'll see

Error: You cannot install a network of sites with your server address.`
You cannot use port numbers such as :8000.

Code changes

  1. Edit wp-admin/includes/network.php to add the port you configured Docker to use, 8000 in my case.
# function network_step1 

if ( ( false !== $has_ports && ! in_array( $has_ports, array( ':80', ':443', ':8000' ), true ) ) ) {
  1. Go to Tools => Network Setup and run through step 3. You'll end up on a page that looks like this Setup messages

  2. Follow the instructions and adjust wp-config.php and .htaccess

  3. At this stage you need to log back into admin. If you try, it won't work. The cookies that are set during the login process don't strip out the port from the host name used with the cookie. You'll need to edit another spot to strip out the port when it assigns the cookie.

# wp-includes/ms-default-constants.php

define( 'COOKIE_DOMAIN', '.' . $current_network->cookie_domain );

=>

define( 'COOKIE_DOMAIN', '.' . str_replace(':8000', '', $current_network->cookie_domain ));

Database changes

  1. Add a new site My Sites => Network Admin => Sites New site fields

  2. It adds the site and strips out the port, so you'll need to log in and adjust the URL in the database directly.

# In wp_2_options (each site will have a table of their own)
- Adjust the `option_name` with the values of `siteurl` and `home`
http://wordpress1.localhost8000
=> 
http://wordpress1.localhost:8000
  1. Make the same adjustment in wp_blogs for the site

  2. You'll now be able to load the site from http://wordpress1.localhost:8000/

Now what?

That is a lot of manual work to make it work well in development. If I needed this to work on a custom port I would look to see if I could work out a way to do it with a plugin. The path I went down in this post will not allow for updating Wordpress easily.

Alternatives to Multisite

If I was looking to setup a true multisite environment, I would lean more strongly towards seeing if using wp-config.php as suggested in this ticket is a viable option.

Multisite is powerful, but it also has some big pieces that make it harder to pick as an option for hosting many web sites with it.

  • A combined wp_users table means all users funnel into one spot. It makes it tricker to segment client data and spin up test environments with "just enough" data.
  • The nomenclature still references them as blogs. It's minor, but it does feel symbolic that the Multisite system has lagged behind with regard to dispelling the feeling that Wordpress is more than just a blog platform.