WordPress Multisite on CentOS

This assumes a current configuration of:

  • CentOS 7.2
  • Apache 2.4
  • PHP 5.6 + Opcache
  • MySQL 5.7

Install WordPress from Subversion

This is the standard quick install. It is advised to do the most recent stable version, and not the main branch, which can break (more) things.

Visit Installing WordPress with Subversion, and look for a command line that looks like:

svn co https://core.svn.wordpress.org/tags/4.7.1 .

The final number will change over time. Currently the options for GIT are a bit malnourished.

Create Database and User

Log into mysql

sudo mysql -u root -p

Create database

CREATE DATABASE wordpress DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;

Create user and grant access to the database (change username and password as appropriate).

GRANT ALL ON wordpress.* TO 'USER'@'localhost' IDENTIFIED BY 'PASSWORD';

FLUSH PRIVILEGES;

EXIT;

Create wp-config.php

First, copy the sample file into a config file

sudo cp /var/www/html/wp-config-sample.php /var/www/html/wp-config.php

Next edit the four parts of the file:

sudo nano /var/www/html/wp-config.php

Change these:

  • Database Name
  • User Name
  • Password
  • Table prefix

Also add the following at the end

/** to set update method, rather than changing file access */
define('FS_METHOD','direct');

Save and restart /index.php

Multisite

WordPress Multisite has advantages (and some disadvantages). The process to change a single site into multisite has several steps.

sudo nano /var/www/html/wp-config.php

Add the following:

/* Multisite */
define( 'WP_ALLOW_MULTISITE', true );

Note that this will then allow you to take the next steps.

  • Administration > Tools > Network Setup
    • Configure for subdomains
  • Once completed, copy the text for .htaccess into httpd.conf (usually this redirection is safe for single site domains as well.
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]
  • Comment out the above item entered into wp-config.php, and instead replace with:
define('MULTISITE', true);
define('SUBDOMAIN_INSTALL', true);
define('DOMAIN_CURRENT_SITE', 'host.domain.com');
define('PATH_CURRENT_SITE', '/');
define('SITE_ID_CURRENT_SITE', 1);
define('BLOG_ID_CURRENT_SITE', 1);
define( 'SUNRISE', 'on' );
  • copy the sunrise.php file to /wp-content/
  • restart Apache
  • change the settings in > Network Admin > Settings > Domain Mapping to 2,5 (the opposite of the default)
  • Add domains to the mapping as desired
  • Set redirections and site defaults to their desired domain name

Other Topics

CentOS Linux

Applications on CentOS