WordPress Multisite Using CloudFlare on Individual Blogs

Trying to set up a WordPress Multisite using CloudFlare on individual blogs? I was. I just moved a WordPress (WP) Multisite subdomain installation and wanted to take full advantage of CloudFlare CDN for each for each of the sites blogs. It’s an awesome service, and free!

Using the lazy route of enabling CloudFlare on my domains via hosting control panel, it requires the www domain name prefix to invoke it’s magic. But the file uploads in a WordPress multisite don’t automatically include this magic.

By default, media uploaded through WP uses the path http://subblog.primaryblogdomain.com – we want to change that to http://www.blogname.com to be served up by CloudFlare.

How-to Instructions for setting up WordPress Multisite Using CloudFlare

In the WP backend (as Super Admin), on the toolbar, go to My Sites/Network Admin/Sites

Edit each site that has been set up on CloudFlare, and select the “Settings” tab.

Change the “site URL” field to be your fully qualified CloudFlare domain, as in http://www.blogname.com and note the blog ID number, from URL when you’re editing each blog. It will end with “site-settings.php?id=X” and we’ll make use of it shortly.

Test an upload to see it uses the proper url. Boom, it’s set!

If you are doing this on an installation that has been moved (i.e. already has posts), you’ll also need to update the posts table in the database. I like to use PHPmyAdmin for this. Hint: Backups are your friend!

Here is the query you’re looking at, where “X” is the ID of the wordpress blog if your tables are named named as mine are; you can easily identify each blog’s ID

UPDATE wp_X_posts SET post_content = replace(post_content, 'subblog.primaryblogdomain.com/wp-content/uploads/', 'www.subblog.com/wp-content/uploads/');

I would suggest leaving the upload path in the SQL command so you don’t inadvertently change something you didn’t want to change. Also, be sure it’s a correct upload path for your setup!

After you’re done, you can also add the CloudFlare WordPress plugin to see to it your stats and so forth accurately reflect your visitors’ locations. You will need to configure the plugin on each site of your installation individually.

I found I also needed to re-save my permalinks in some cases. I’m not sure if it was this operation that created the need or not. I was doing a lot of work on my install at the time, but if you’re getting 404 errors with post titles, give that a try.

That’s it–configuring Wordpress Multisite Using CloudFlare is not so difficult.   Unless you have some image paths hard-coded in your themes, plugin or widget code, your WordPress should now serve all your images from Cloudflare instead of the local server. No plugins, no headaches. Just a little configuration change and some mySQL voodoo.

FYI, this information is offered AS IS, in the hopes it is of help to someone. If you break your Wordpress, I cannot fix it for you. I cannot answer WP support questions. This is what worked for me, period. Thanks for understanding.

Share Button

SQL: Closing Comments on WordPress Installation

During domain propagation when changing hosts for a WordPress blog, you may want to close comments to keep from losing anything. While you can certainly use the WP comment template technique, this is an especially convenient way of turning off comments en masse on a WP installation.

After transferring the blog databases to the new host, access PHPmyAdmin on the old host with this bit of SQL; if you have a different prefix to your table that “wp_” you’ll need to adjust the command accordingly.

UPDATE wp_posts p SET comment_status = 'closed', ping_status = 'closed' WHERE comment_status = 'open'

This approach also makes it very easy for a client to check domain propagation. If the comments are closed, the site is being served from the old host. If comments are open, it’s being  served from the new host. Easy!

Share Button

Transferring Databases via SSH Command Line

Command Line Fu has a solution for those who have SSH access and need to move a database:

To create a new database with a different name:

ssh -C user@newhost "mysql -uUSER -pPASS -e 'create database NEW_DB_NAME;'" && mysqldump --force --log-error=mysql_error.log -uUSER -pPASS OLD_DB_NAME | ssh -C user@remotehost "mysql -uUSER -pPASS NEW_DB_NAME"

To use the same database name for target as the source:

mysqldump --databases --force --log-error=/root/mysql_error.log -uUSER -pPASS OLD_DB_NAME | ssh -C user@newhost "mysql -uUSER -pPASS"

If you’re using SSH on a non-standard port (recommended), you’ll need to add a parameter for it in your code after the ssh command, such as -p XXX, where “XXX” is replaced by your port number.

Share Button