Setup sub-directories Multisite

How to setup a sub-directories Wordpress Multisite network

How to setup a Wordpress Multisite network

In this how-to we’ll describe a sub-directories Multisite setup. Assuming you’ve already created and setup a Wordpress site using a wordpress-runtime image as a base, proceed with the following steps:

1. Enable Nginx rewrite rules for multisite

Simply add STACK_MULTISITE_RULES=subfolder to your environment variables.

2. Locate the application.php file in your site’s source project

You should find it in the config directory, at the following path: <project_root>/config/application.php

3. Allow a Multisite setup to be activated

In the application.php file, right before a line saying Config::apply();, add the following:

Config::define('WP_ALLOW_MULTISITE', true);

4. Build and redeploy the site with the change you’ve just made

5. Activate the Multisite setup

Log in to your site’s Wordpress admin panel, and navigate to Tools -> Network Setup. The url should be something like: <yoursite.com>/wp/wp-admin/network.php.

There you can choose between a sub-domain Multisite setup or a sub-directories one. Choose sub-domain Multisite setup, but make sure it is what you want, as it is a hassle to change later.

There are a few other things you can configure such as the Network Title and Network Admin Email.

After you are done with those, press the Install button.

You’ll then be presented with instructions on how to finish the setup, but we’re going to use a different, albeit similar configuration, so you may ignore them.

6. Add the final configuration

In the application.php file you edited earlier, also add the following snippet, right after the WP_ALLOW_MULTISITE line which you’ve added earlier:

Config::define('MULTISITE', true);
Config::define('SUBDOMAIN_INSTALL', false);
Config::define('DOMAIN_CURRENT_SITE', env('DOMAIN_CURRENT_SITE') ?: explode(',', env('STACK_ROUTES'))[0]);
Config::define('PATH_CURRENT_SITE', env('PATH_CURRENT_SITE') ?: '/');
Config::define('SITE_ID_CURRENT_SITE', env('SITE_ID_CURRENT_SITE') ?: 1);
Config::define('BLOG_ID_CURRENT_SITE', env('BLOG_ID_CURRENT_SITE') ?: 1);

7. Build and redeploy the site again, with the lines you’ve just added

8. Log out and in again to the site’s Wordpress admin panel

9. Navigate to the Network Admin -> Sites section

A new button with the text My Sites should have appeared in the header bar of the admin panel. Hover on it, to activate the dropdown menu. Hover on to the Network Admin entry from the dropdown menu, and select Sites from the additional sub-menu.

If you can’t find it, the URL should be something similar to <yoursite.com>/wp/wp-admin/network/sites.php.

From here you will be able to manage your (multi) Sites.