Chapter 2

Setting Up and Configuring Network Features

IN THIS CHAPTER

Check Enabling the network

Check Configuring the network installation

Check 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:

  • Backups of your site (explained in Book 2, Chapter 7)
  • Access to the wp-config.php file for editing (Book 2, Chapter 5)
  • Enabled wildcard subdomains (covered in Book 8, Chapter 1) if you're using subdomains

Enabling the Network Feature

You need to enable access to the Network menu so you can set up the network and allow the creation of multiple sites.

Warning It’s a good idea to download a copy of the original wp-config.php file your web server and store it on your computer to keep it safe. That way, if you make any mistakes or experience any errors after altering it, you can easily upload the original and start over.

Warning If you have any plugins installed and activated on your WordPress installation, deactivate them before you proceed with the network setup. WordPress won’t allow you to continue until you deactivate all your plugins.

Follow these steps:

  1. 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.

  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.

  3. Click at the end of the line that reads define( 'DB_COLLATE', '' ); and then press Enter (or Return on a Mac) to create a new blank line.
  4. Type the following on the new blank line:

    define( 'WP_ALLOW_MULTISITE', true );

  5. Save the file to your computer as wp-config.php.
  6. Upload the new file to your web server in your WordPress installation directory.
  7. Go to your WordPress Dashboard in your browser.

    You see a new item, labeled Network Setup, on the Tools menu.

  8. 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.

Screenshot displaying the Network details section of the Create a Network of WordPress Sites screen in the WordPress Dashboard with options to be filled in.

FIGURE 2-1: The Create a Network of WordPress Sites screen in your WordPress Dashboard.

Exploring the Difference between Subdirectories and Subdomains

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.

Remember In some cases, depending on your setup, your choice may be limited. WordPress does some autodetection with information about your installation and may prevent you from choosing an option that won’t work with your setup.

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 https://localhost.

Site URL is an IP address.

WordPress is installed in a folder (such as http://domain.com/wp).

The Network can use subdirectories only.

WordPress is installed in the root of the domain (http://domain.com).

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.

Tip If you want your extra sites to have separate domain names, you still need to pick one of these options. Book 8, Chapter 6 covers top-level domains.

Installing the Network on Your Site

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):

  1. 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.

  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.

    Warning 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.

    Tip 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.

  3. 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]

    Remember 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.

  4. 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.

  5. Save the .htaccess file, and upload it to your web server.
  6. 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.

  7. Log in to WordPress by entering your username and password in the login form.
Screenshot displaying the Enabling the Network section of the Create a Network of WordPress Sites screen in the WordPress Dashboard with network-related configuration lines.

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.)

Disabling the Network

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.

Remember WordPress adds new tables each time you add a new site to your network. Those database tables are assigned unique numbers incrementally.

Dealing with Common Errors

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:

  1. Delete the extra sites, if any were created.
  2. 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.

  3. Save the wp-config.php file, and upload it to your website.
  4. 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.

Remember You can’t perform this process if you want to keep extra sites.