Menu Close

WordPress multi site set up

What is Multisite? The WordPress Codex defines Multisite as:

 “A feature of WordPress 3.0 and later versions that allows multiple virtual sites to share a single WordPress installation.”

This means that by installing WordPress just once on your server, you can run as many sites as you want. Currently WordPress.com hosts approximately 37 million sites, and WPMUDEV’s Edublogs.org hosts nearly 3 million educational sites.

From those case, you may imagine  making some money through the WordPress multi site from people or setting up your conventional own infrastructure such as customer website or company sites. Whatever your reasons for choosing multi site, it is good for your mental health & finger’s labor.

Also there are whole bunch of know-hows and documents for multi site building at our network world, and I am just telling you on points  and method.

  1. Install main web site with wordpress
  2. Edit and add below code at the wp-config.php file:
    /* Multisite settings */
    define( ‘WP_ALLOW_MULTISITE’, true );
  3. save wp-config.php and goto Admin panel
  4. Tools > Network Setup –> Install
  5. Choose the sub-domains or sub-directories option. Modify your network title as desired.
  6. You will be presented with two blocks of code to be added in the wp-config.php and .htaccess files. Copy the wp-config.php code which looks similar to the following:
    define(‘MULTISITE’, true);
    define(‘SUBDOMAIN_INSTALL’, true);
    define(‘DOMAIN_CURRENT_SITE’, ‘examplewp.com’);
    define(‘PATH_CURRENT_SITE’, ‘/’);
    define(‘SITE_ID_CURRENT_SITE’, 1);
    define(‘BLOG_ID_CURRENT_SITE’, 1);
  7. You should replace server’s .htaccess with below context. (Apache user)RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ – [L]
    # add a trailing slash to /wp-admin
    RewriteRule ^wp-admin$ wp-admin/ [R=301,L]
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^ – [L]
    RewriteRule ^(wp-(content|admin|includes).*) $1 [L]
    RewriteRule ^(.*\.php)$ $1 [L]
    RewriteRule . index.php [L]
  8. In case of Nginx user, just ignore .htaccess context, as Nginx does not have this file. (Be carefulr, Nginx use general regulation expression for configuration. So you have to adjust or keep that in mind. )
  9. save both files, and log out –> re log in. You can directly catch the control situation and will get your all sites. Also you can add new one.
  10. Have to adjust domain mapping for commercial or business manner. For this we need a plugin (WordPress-mu-domain-mapping)
  11. After installing above plugin, copy the sunrise.php file from the plugin’s directory to the wp-content directory. Edit the wp-config.php file and add the following line before the comment /* That’s all, stop editing! Happy blogging. */.
    define(‘SUNRISE’, ‘on’);
  12. For easy usage the plugin, let’s do work.
    (1) wordpress/wp-content/mu-plugins : make directory
    (2) wp-content/mu-plugins/wpms_blogid.php : create file  – file content as follow and this file checks the site ID for plugin
    <?php
    add_filter( ‘wpmu_blogs_columns’, ‘do_get_id’ );
    add_action( ‘manage_sites_custom_column’, ‘do_add_columns’, 10, 2 );
    add_action( ‘manage_blogs_custom_column’, ‘do_add_columns’, 10, 2 );
    function do_add_columns( $column_name, $blog_id ) {
    if ( ‘blog_id’ === $column_name )
    echo $blog_id;
    return $column_name;
    }
    function do_get_id( $columns ) {
    $columns[‘blog_id’] = ‘ID’;
    return $columns;
    }
  13. Add your site.

How to multisite Installation with WP-CLI

To make your wp work with a multi site WordPress installation, you just need to pass the –url argument as so:

$ wp theme status –url=localhost/wp/test
   # For a subdomain just specify the url
$ wp theme status –url=subdomain.my-wordpress-site.com

If you want wp to remember your –url configuration, you can specify it in a wp-cli.yml, which must be located inside your WordPress root.  Add the following to your wp-cli.yml:

url: test.example.com
You will now be able to omit the –url argument from your wp commands, e.g.:

$ wp theme status
This will read the configuration from the wp-cli.yml and pass the –url test.example.com for you.

Some useful and valuable sources