Chapter 2
IN THIS CHAPTER
Enabling the network
Configuring the network installation
Disabling the network
This chapter covers how to find the files you need to edit the network, how to enable multiple sites in the network, and how to remove the network should you no longer want to have multiple sites in your WordPress install.
By default, access to network settings is disabled to ensure that users don’t set up their network without researching all that the setup entails. Setting up a network involves more than configuring options or turning on a feature, so before enabling and setting up a network, be sure that you read Book 8, Chapter 1.
Here’s what you need:
You need to enable access to the Network menu so you can set up the network and allow the creation of multiple sites.
Follow these steps:
Download the file called wp-config.php
from the WordPress installation on your web server.
It's easiest to use an SFTP program to download a copy of this file from your web server to your computer. If you need a refresher on SFTP, refer to Book 2, Chapter 2.
Using your preferred text editor, open the wp-config.php
file.
Windows users can use Notepad to edit the file; Mac users can use TextEdit.
define( 'DB_COLLATE', '' );
and then press Enter (or Return on a Mac) to create a new blank line.define( 'WP_ALLOW_MULTISITE', true );
wp-config.php
.Go to your WordPress Dashboard in your browser.
You see a new item, labeled Network Setup, on the Tools menu.
Click the Network Setup link on the Tools menu.
The Create a Network of WordPress Sites screen displays. (It's covered in the next section and shown in Figure 2-1.) You also see a reminder to deactivate all your plugins before continuing with network setup.
FIGURE 2-1: The Create a Network of WordPress Sites screen in your WordPress Dashboard.
Before you start setting up the network, the Create a Network of WordPress Sites screen informs you that your installation isn’t new and that the sites in your WordPress network must use subdomains as opposed to subdirectories (refer to Figure 2-1). During the Network installation process (covered in the next section of this chapter), you can make a change in the configuration if you want to use a subdirectory setup as opposed to a subdomain.
Table 2-1 explains some of the limitations you may encounter as you try to enable a subdomain or subdirectory format.
TABLE 2-1 Common Network Setup Situations
Situation |
Format |
Site URL is different from home URL. |
Network can’t be enabled. |
Site URL is Site URL is an IP address. WordPress is installed in a folder (such as |
The Network can use subdirectories only. |
WordPress is installed in the root of the domain ( |
Subdomains are the default, but you can choose either. |
Site addresses generate in a similar way; they're virtual. They don’t physically exist in your file directory on your web server, and you won’t see them in the directory structure on your web server because they’re served to the browser virtually when that site is requested. From a technical standpoint, subdomains require an extra step in server setup for the wildcards. (Book 8, Chapter 1 covers setting up wildcard subdomains on the server side.) Subdomains are somewhat separated from the main domain, at least in terms of content. Subdirectories, on the other hand, are part of the main domain, as though they were pages off the main site.
Because each site’s URL is saved in its tables in the database, after you pick the subsites you want to create, you can’t switch from subdirectories to subdomains (or vice versa) without reinstalling the network.
Each site format (subdomain or subdirectory) offers certain search engine optimization (SEO) benefits. Search engines read subdomains as separate sites on your web host; therefore, the subdomains maintain their page rank and authority, and search engines list multiple results for your domain. Subdirectories are read as pages or sections off your main domain. They also help the main domain’s page rank and authority, and provide one result for your domain in search engines.
The Network Details section of the Create a Network of WordPress Sites page (refer to Figure 2-1 earlier in this chapter) has options that are filled in automatically. The server address, for example, is pulled from your installation and can’t be edited. The network title and administrator’s email address are pulled from your installation database, too, because your initial WordPress site is the main site of the network.
Follow these steps to complete the installation (and be sure to have your preferred text-editor program handy):
Click the Install button at the bottom of the Create a Network of WordPress Sites screen of your WordPress Dashboard.
The Enabling the Network screen opens, as shown in Figure 2-2.
Add the required network-related configuration lines to the wp-config.php
file following the define( 'WP_ALLOW_MULTISITE', true );
code you added earlier.
On the Enabling the Network screen, WordPress gives you up to six lines of configuration rules that need to be added to the wp-config.php
file. The lines of code you add may look like this:
define( 'MULTISITE', true );
define( 'SUBDOMAIN_INSTALL', true );
define( 'DOMAIN_CURRENT_SITE', 'domain.com' );
define( 'PATH_CURRENT_SITE', '/' );
define( 'SITE_ID_CURRENT_SITE', 1 );
define( 'BLOG_ID_CURRENT_SITE', 1 );
These lines of code provide configuration settings for WordPress by telling WordPress whether it's using subdomains, what the base URL of your website is, and what your site’s current path is. This code also assigns a unique ID of 1
to your website for the main installation site of your WordPress Multisite network.
The lines of code that appear on the Enabling the Network screen are unique to your installation of WordPress. Make sure that you copy the lines of code on the Create a Network of WordPress Sites screen of your installation because they’re specific to your site’s setup.
My WordPress installation sets up my network to use subdomains instead of subdirectories. If you’d like to use subdirectories, change
define( 'SUBDOMAIN_INSTALL', true );
to define( 'SUBDOMAIN_INSTALL', false );
. Make sure that you have the <VirtualHost>
and Apache mod_rewrite
configurations on your server in place first; I cover both configurations earlier in this chapter.
Add the rewrite rules to the .htaccess
file on your web server.
WordPress gives you several lines of code to add to the .htaccess
file on your web server in the WordPress installation directory. The lines look something like this:
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]
In Book 8, Chapter 1, I discuss the required Apache module
mod_rewrite
, which you must have installed on your web server to run WordPress Multisite. The rules that you add to the .htaccess
file on your web server are mod_rewrite
rules, and they need to be in place so that your web server tells WordPress how to handle things like permalinks for posts, pages, media, and other uploaded files. If these rules aren't in place, the WordPress Multisite feature won’t work correctly.
Copy the lines of code that you entered in step 3, open the .htaccess
file, and paste the code there.
Replace the rules that already exist in that file.
.htaccess
file, and upload it to your web server.Return to your WordPress Dashboard, and click the Log In link at the bottom of the Enabling the Network screen.
You're logged out of WordPress because by following these steps, you changed some of the browser cookie-handling rules in the wp-config.php
and .htaccess
files.
FIGURE 2-2: The Enabling the Network screen.
With the Multisite feature enabled, you see a link to My Sites. If you hover your mouse pointer over that link, the Network Admin link appears on the drop-down menu in the top-left corner of the Dashboard. The Network Admin Dashboard is where you, as the site owner, administer and manage your multisite WordPress network. (See Book 8, Chapter 3.)
At some point, you may decide that running a network of sites isn't for you, and you may find that you want to disable the Multisite feature. Before disabling the network, you want to save any content from the other sites by making a full backup of your database. Book 2, Chapter 7 has detailed information about backing up your site.
The first step is restoring the original wp-config.php
file and .htaccess
files that you saved earlier. (Refer to “Enabling the Network Feature” earlier in this chapter.) This step causes your WordPress installation to stop displaying the Network Admin menu and the extra sites.
You also may want to delete the tables that were added, which permanently removes the extra sites from your installation. Book 2, Chapter 3 takes you through the WordPress database, including the use of a popular database administration tool called phpMyAdmin. You can use that tool to delete the Multisite tables from your WordPress database when you want to deactivate the feature. The extra database tables that are no longer required when you aren't running the WordPress Multisite feature include
wp_blogs
: This database table contains one record per site and is used for site lookup.wp_blog_versions
: This database table is used internally for upgrades.wp_registration_log
: This database table contains information on sites created when a user signed up if he chose to create a site at the same time.wp_signups
: This database table contains information on users who signed up for the network.wp_site
: This database table contains one record per WordPress network.wp_sitemeta
: This database table contains network settings.Additionally, you can delete any database tables that have blog IDs associated with them. These tables start with prefixes that look like wp_1_
, wp_2_
, wp_3_
, and so on.
Occasionally, you may enter a configuration setting incorrectly or change your mind about the kind of network you require. If you installed WordPress, enabled the network, and then want to move it to a new location, you'll encounter errors when changing the URL. The proper method is to move WordPress first, disable the network if you installed it, and then enable the network at the new location.
To change from subdomains to subfolders, or vice versa, follow these steps:
Edit wp-config.php
, changing the value of define( 'SUBDOMAIN_INSTALL', true );
to define( 'SUBDOMAIN_INSTALL', false );
.
To switch from subdomains to subdirectories, change false
to true
.
wp-config.php
file, and upload it to your website.Visit the Dashboard of WordPress, click the Permalink link on the Settings menu, and click the Save Changes button.
This step saves and resets your permalink structure settings and flushes the internal rewrite rules, which are slightly different for subdomains than they are for subdirectories.