Search code examples
wordpressdockermultisite

Docker wordpress multisite - what ports to expose?


I'm trying to set up Wordpress multisite /as a network in a Docker container. From the docs, I understand that multisite only works with port 80 and 443.

When I use port 8000 for the wpmu service as below, I can access wordpress

docker-compose.yml

version: '3.3'

services:
  db:
    image: mysql:5.7
    volumes:
      - db_data:/var/lib/mysql
    restart: always
    ports:
    - "3306:3306"
    environment:
      MYSQL_ROOT_PASSWORD: root_password
      MYSQL_DATABASE: wpmu_db
      MYSQL_USER: wpmu_db_user
      MYSQL_PASSWORD: wpmu_db_user_password

  phpmyadmin:
    depends_on:
      - db
    image: phpmyadmin/phpmyadmin
    restart: always
    ports:
      - "8080:80"
    environment:
      PMA_HOST: db
      MYSQL_ROOT_PASSWORD: root_password

  wpmu:
    depends_on:
      - db
    image: wordpress:latest
    ports:
      - "8000:80"
    restart: always
    volumes:
      - ".wp/:/var/www/html"
    environment:
      WORDPRESS_DB_HOST: db:3306
      WORDPRESS_DB_USER: wpmu_db_user
      WORDPRESS_DB_PASSWORD: wpmu_db_user_password
      WORDPRESS_DB_NAME: wpmu_db
      WORDPRESS_CONFIG_EXTRA: define('WP_ALLOW_MULTISITE', true );

volumes:
  db_data: {}

When I navigate to http://localhost:8000/wp-admin/network.php, I get

Create a Network of WordPress Sites

ERROR: You cannot install a network of sites with your server address.

You cannot use port numbers such as :8000.

If I change the port from 8000 to 80 or 443, the service no longer works (I get a "this page isn't working - localhost didn't send any data" and a 404 respectively).

Any idea how to set the ports for multisite to work?


Solution

  • I am using Wordpress 5.3.1 on Docker and manage to fix it by adding my exposed port to a list of allowed ports in wp-admin/includes/network.php.
    Look for the below code:

    if ( ( false !== $has_ports && ! in_array( $has_ports, array( ':80', ':443') ) ) )

    and change it to include your port:

    if ( ( false !== $has_ports && ! in_array( $has_ports, array( ':80', ':443', ':8000') ) ) )