Bobcares

Docker wordpress multisite

by | Apr 25, 2022

Wondering how to create Docker wordpress multisite? We can help you.

At Bobcares, we offer solutions for every query, big and small, as a part of our Server Management Service.

Let’s take a look at how our Support Team assist with this query.

How to create Docker wordpress multisite?

Today, let us see the steps followed by our Support techs:

Create a Dockerfile

Firstly, create a Dockerfile for our custom WP image.

Make sure to use the default name “Dockerfile” so docker-compose knows what to do.

FROM wordpress:latest
COPY wp-config-sample.php /usr/local/bin/
COPY wordpress-entrypoint.sh /usr/local/bin/
ENTRYPOINT ["wordpress-entrypoint.sh"]
CMD ["apache2-foreground"]

The first line says we are inheriting everything from the “wordpress:latest” image.

The next line puts the wp-config-sample.php file that we will modify in a safe place until the entrypoint script runs.

If we tried to put it in /var/www/html it would get written over when WordPress is downloaded into that directory.

The second COPY line puts our custom entrypoint script into the container.

The ENTRYPOINT line runs our custom entrypoint script, which is just the default docker-entrypoint.sh script with a minor change we will make.

And finally, the CMD line runs our Apache server.

Modify wp-config-sample.php

Add the following just above “/* That’s all, stop editing! Happy blogging. */” to a clean copy of wp-config-sample.php:

define('WP_ALLOW_MULTISITE', true);

Create the Entrypoint Script

The default entrypoint script is located in the same directory as the Dockerfile on GitHub.

Then, copy the contents of this file into a new one called wordpress-entrypoint.sh and add the following after line 52:

# Overwrite wp-config-sample.php with the multisite version
mv -f /usr/local/bin/wp-config-sample.php /var/www/html/wp-config-sample.php


Create and run docker-compose.yml

version: '3.1'
services:

  wordpress:
    build: .
    image: wordpress-multisite
    environment:
      WORDPRESS_TABLE_PREFIX: wp_
      WORDPRESS_DB_PASSWORD: mysecurepwd
      WORDPRESS_DEBUG: 'true' 
    ports:
      - '80:80'
    volumes:
      - wordpress:/var/www/html
      - ./themes:/var/www/html/wp-content/themes
      - ./.htaccess:/var/www/html/.htaccess
    depends_on:
      - mysql

  mysql:
    image: mariadb
    environment:
      MYSQL_ROOT_PASSWORD: mysecurepwd
    ports:
      - '3306:3306'
    volumes:
      - db-data:/var/lib/mysql

  volumes:
    wordpress:
    db-data:

Setting up the volumes isn’t entirely necessary, but it’s nice to have them named something sensible like “wordpress” and “db-data” rather than a random string when you run a “docker volume ls” command like we will do later.

Also, we created a mounted volume for our themes directory since this is likely what we’ll modifying in a development environment.

After saving your compose file, run:

docker-compose up -d

Install WordPress

Go to http://localhost in a browser and you should see the familiar WordPress installation wizard.

If something goes wrong you can troubleshoot by viewing your wp-config.php file in the running wordpress container by entering: docker exec -it [your folder name]_wordpress_1 /bin/bash

This should take you to a shell prompt in your container and you can view your file by running: cat wp-config.php.

The first thing I would look for is to see if WP_DEBUG is set to ‘true’ instead of the default ‘false’ value.

Enter your language, username, password, etc.

Log in after the installation is complete and enable Multisite by navigating to Tools > Network Setup.

After clicking “Install”, WordPress will give you some instructions on how to enable the network by changing wp-config.php and .htaccess.

This is what we will do next.

Modify wp-config-sample.php

Add the lines from the admin screen to wp-config-sample.php above the line reading /* That’s all, stop editing! Happy blogging.

They should look something like this:

define('MULTISITE', true);
define('SUBDOMAIN_INSTALL', false);
define('DOMAIN_CURRENT_SITE', 'localhost');
define('PATH_CURRENT_SITE', '/');
define('SITE_ID_CURRENT_SITE', 1);
define('BLOG_ID_CURRENT_SITE', 1);

Create an .htaccess file

Copy the text from the admin into a file named .htaccess It should look like this:

RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteRule . index.php [L]

Modify docker-compose.yml

Under the wordpress volumes section add the following line which will override the default .htaccess file with the new one.

- ./.htaccess:/var/www/html/.htaccess

Rebuild the WordPress Image

Now we have to clean up our docker environment by stopping the processes:

docker-compose down

Removing our wordpress-multisite image:

docker image rm wordpress-multisite

Removing our wordpress volume: (you can get your volume’s name by running docker volume ls)

docker volume rm [volume name]

Now that everything has been cleaned up, we can re-run:

docker-compose up -d

This will rebuild our WordPress image and volume with the updated wp-config.php file and our new .htaccess file.

Bask in the Glory of WordPress Multisite using Docker

When you log back into your WordPress Admin, hover over “My Sites” in the top-left.

If all has gone well, Network Admin will be the first link you see.

[Looking for a solution to another query? We are just a click away.]

Conclusion

To sum up, our skilled Support Engineers at Bobcares demonstrated how to create Docker wordpress multisite

1 Comment

  1. Mac

    According to github’s Dockerfile, the entry file is named as ‘docker-entrypoint.sh` instead of `wordpress-entrypoint.sh`.

    Reply

Submit a Comment

Your email address will not be published. Required fields are marked *

Never again lose customers to poor
server speed! Let us help you.

Privacy Preference Center

Necessary

Necessary cookies help make a website usable by enabling basic functions like page navigation and access to secure areas of the website. The website cannot function properly without these cookies.

PHPSESSID - Preserves user session state across page requests.

gdpr[consent_types] - Used to store user consents.

gdpr[allowed_cookies] - Used to store user allowed cookies.

PHPSESSID, gdpr[consent_types], gdpr[allowed_cookies]
PHPSESSID
WHMCSpKDlPzh2chML

Statistics

Statistic cookies help website owners to understand how visitors interact with websites by collecting and reporting information anonymously.

_ga - Preserves user session state across page requests.

_gat - Used by Google Analytics to throttle request rate

_gid - Registers a unique ID that is used to generate statistical data on how you use the website.

smartlookCookie - Used to collect user device and location information of the site visitors to improve the websites User Experience.

_ga, _gat, _gid
_ga, _gat, _gid
smartlookCookie
_clck, _clsk, CLID, ANONCHK, MR, MUID, SM

Marketing

Marketing cookies are used to track visitors across websites. The intention is to display ads that are relevant and engaging for the individual user and thereby more valuable for publishers and third party advertisers.

IDE - Used by Google DoubleClick to register and report the website user's actions after viewing or clicking one of the advertiser's ads with the purpose of measuring the efficacy of an ad and to present targeted ads to the user.

test_cookie - Used to check if the user's browser supports cookies.

1P_JAR - Google cookie. These cookies are used to collect website statistics and track conversion rates.

NID - Registers a unique ID that identifies a returning user's device. The ID is used for serving ads that are most relevant to the user.

DV - Google ad personalisation

_reb2bgeo - The visitor's geographical location

_reb2bloaded - Whether or not the script loaded for the visitor

_reb2bref - The referring URL for the visit

_reb2bsessionID - The visitor's RB2B session ID

_reb2buid - The visitor's RB2B user ID

IDE, test_cookie, 1P_JAR, NID, DV, NID
IDE, test_cookie
1P_JAR, NID, DV
NID
hblid
_reb2bgeo, _reb2bloaded, _reb2bref, _reb2bsessionID, _reb2buid

Security

These are essential site cookies, used by the google reCAPTCHA. These cookies use an unique identifier to verify if a visitor is human or a bot.

SID, APISID, HSID, NID, PREF
SID, APISID, HSID, NID, PREF