Tuesday, October 7, 2014

How to change a Multisite primary domain -- before and then after installing Mutlisite

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 974
Server version: 5.5.38-0ubuntu0.14.04.1 (Ubuntu)

Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| cthb               |
| mysql              |
| performance_schema |
+--------------------+
4 rows in set (0.00 sec)

mysql> use cthb;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> show tables;
+-----------------------+
| Tables_in_cthb        |
+-----------------------+
| ct_blog_versions      |
| ct_blogs              |
| ct_commentmeta        |
| ct_comments           |
| ct_links              |
| ct_options            |
| ct_postmeta           |
| ct_posts              |
| ct_registration_log   |
| ct_signups            |
| ct_site               |
| ct_sitemeta           |
| ct_term_relationships |
| ct_term_taxonomy      |
| ct_terms              |
| ct_usermeta           |
| ct_users              |
+-----------------------+
17 rows in set (0.00 sec)

mysql> select siteurl from ct_options;
ERROR 1054 (42S22): Unknown column 'siteurl' in 'field list'
mysql> desc ct_options;
+--------------+---------------------+------+-----+---------+----------------+
| Field        | Type                | Null | Key | Default | Extra          |
+--------------+---------------------+------+-----+---------+----------------+
| option_id    | bigint(20) unsigned | NO   | PRI | NULL    | auto_increment |
| option_name  | varchar(64)         | NO   | UNI |         |                |
| option_value | longtext            | NO   |     | NULL    |                |
| autoload     | varchar(20)         | NO   |     | yes     |                |
+--------------+---------------------+------+-----+---------+----------------+
4 rows in set (0.00 sec)

mysql> desc ct_site;
+--------+--------------+------+-----+---------+----------------+
| Field  | Type         | Null | Key | Default | Extra          |
+--------+--------------+------+-----+---------+----------------+
| id     | bigint(20)   | NO   | PRI | NULL    | auto_increment |
| domain | varchar(200) | NO   | MUL |         |                |
| path   | varchar(100) | NO   |     |         |                |
+--------+--------------+------+-----+---------+----------------+
3 rows in set (0.00 sec)

mysql> select domain from ct_site;
+----------------------+
| domain               |
+----------------------+
| www.singingtorah.com |
+----------------------+
1 row in set (0.00 sec)

mysql> update ct_site set domain='singingtorah.org';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> commit;
Query OK, 0 rows affected (0.00 sec)

mysql> desc ct_blogs;
+--------------+--------------+------+-----+---------------------+----------------+
| Field        | Type         | Null | Key | Default             | Extra          |
+--------------+--------------+------+-----+---------------------+----------------+
| blog_id      | bigint(20)   | NO   | PRI | NULL                | auto_increment |
| site_id      | bigint(20)   | NO   |     | 0                   |                |
| domain       | varchar(200) | NO   | MUL |                     |                |
| path         | varchar(100) | NO   |     |                     |                |
| registered   | datetime     | NO   |     | 0000-00-00 00:00:00 |                |
| last_updated | datetime     | NO   |     | 0000-00-00 00:00:00 |                |
| public       | tinyint(2)   | NO   |     | 1                   |                |
| archived     | tinyint(2)   | NO   |     | 0                   |                |
| mature       | tinyint(2)   | NO   |     | 0                   |                |
| spam         | tinyint(2)   | NO   |     | 0                   |                |
| deleted      | tinyint(2)   | NO   |     | 0                   |                |
| lang_id      | int(11)      | NO   | MUL | 0                   |                |
+--------------+--------------+------+-----+---------------------+----------------+
12 rows in set (0.00 sec)

mysql> select domain from ct_blogs;
+----------------------+
| domain               |
+----------------------+
| www.singingtorah.com |
+----------------------+
1 row in set (0.00 sec)

mysql> update ct_blogs set domain='singingtorah.org';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> commit;
Query OK, 0 rows affected (0.00 sec)

mysql> commit;

How to change a Multisite primary domain

  
If you want to change the primary domain of your WordPress multisite installation, there are 5 values to change. There is no need to perform a database dump. This is actually frowned upon, as WordPress stores serialized data in the database, and altering it can cause corruption. Here is a list of the 5 main tables and options that need to be changed (note that we’re assuming your table prefix is “wp_”. If you’re using a different table prefix, replace “wp_” in the following table names with your prefix):
  • wp_options: options named “siteurl” and “home”
  • wp_site
  • wp_sitemeta: the option named “siteurl”
  • wp_blogs: any entries in the “domains” column that have the old domain name
  • wp_#_options: Each sub-site will have sets of tables that correspond to the blog_id in the wp_blogs table. You need to go to the wp_#_options table, where # corresponds to the blog_id, and update the “siteurl” and “home” settings in that table.
In order to make these changes, you’ll need to utilize phpmyadmin to edit your database.
Using the above bullet points – find the necessary tables, which are pointed out below and edit the URLs to the new domain you’re wanting:
mu-db-tables

Be sure to mirror the current syntax of HTTP or nonHTTP for each table. Here are two examples below of the wp_site table using nonHTTP and wp_sitemetausing HTTP:
update-wp-site
update-sitemeta

WordPress has different rules for different fields. The wp_site and wp_blogs tables can NOT have http:// or a trailing slash at the end of the domain name, whereas in the wp_options table, it is required to have the http:// at the beginning. In the wp_sitemeta table it is required to have http:// at the beginning and a trailing slash at the end.
Also make sure to comment out any pre-defined constants in your wp-config.php file, as they will override settings in the database. Things such as:
define( 'WP_HOME', 'http://example.com' );
define( 'WP_SITEURL', 'http://example.com' );
After that, we have to manually tell our servers which domain is the new primary domain. We can make this change, and push it out in under a couple of seconds.
Note: In most cases you may/will need to update a entry in your WP-Config.php file. The code I would recommend taking a look at is the code snippet here:
define('WP_ALLOW_MULTISITE', true);
define( 'MULTISITE', true );
define( 'SUBDOMAIN_INSTALL', true );
$base = '/';
define( 'DOMAIN_CURRENT_SITE', 'mysite.wpengine.com' );
define( 'PATH_CURRENT_SITE', '/' );
define( 'SITE_ID_CURRENT_SITE', 1 );
define( 'BLOG_ID_CURRENT_SITE', 1 );
On the line that has “define(‘DOMAIN_CURRENT_SITE’,’mysite.wpengine.com’);”
You will replace “mysite.wpengine.com” with your domain. So for example:
define('WP_ALLOW_MULTISITE', true);
define( 'MULTISITE', true );
define( 'SUBDOMAIN_INSTALL', true );
$base = '/';
define( 'DOMAIN_CURRENT_SITE', 'mysite.com' );
define( 'PATH_CURRENT_SITE', '/' );
define( 'SITE_ID_CURRENT_SITE', 1 );
define( 'BLOG_ID_CURRENT_SITE', 1 );

No comments:

Post a Comment