Hosting Subdomain on a Different Server than Main Domain

There may be times where you want to host a subdomain on a different server than the main domain. To accomplish this, you need an A record, added either at the domain registrar if possible, or the server that hosts mydomain.com.

sub.mydomain.com. 14400 IN  A  XXX.XXX.XXX

The X’s should be replaced by the target server’s IP address. I prefer changing this info at the domain record level, since that doesn’t require cooperation of the main domain’s host, and thus can be changed by the domain owner in the event the target server’s IP changes.

For this to work, the subdomain MUST be added to the target server. A very simple way to do this is to add the main domain as an Addon in cPanel, and then set up the subdomain which will add all the relevant DNS entries (even though the main domain is not actually hosted on the target server). ((Caveat – I’ve found you may see occasional weirdness, though, with the approach described, such as a WordPress installation that requires uploads to go straight to the upload folder to work, instead of month and year-based folder settings. Would probably be better to add the subdomain to your server configuration directly for long-term robustness.))

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

Mass Delete Pending Spam Comments from WordPress Database

If you’ve got 14,500 and some pending spam comments in your WP database, I feel your pain. I just transferred a WP site in exactly that state.

Fortunately, you don’t have to scroll through hundreds of pages of the comments moderation que, clicking away to get rid of the junk. A simple line of SQL is all you need to conquer the  spam dragon in a matter of mere seconds. Pop this query into something like PHPmyAdmin where you can run SQL statements directly, and you’re golden.

DELETE FROM wp_comments WHERE comment_approved = '0'

Ideally, run this on the source database before transfer to make your life easier. Why would you want to move thousands of spam comments anyway, right? As a plus, you may be able to import your database using PHPmyAdmin if you can get your database dump to a reasonable file size via deleting an out-of-control spamfest.

Note:  This command will delete ALL unapproved comments. No second chances, review or confirmation. Make sure that’s your goal before you go running SQL statements all willy-nilly. The management is not responsible for outcomes. Use the force wisely, Luke.

Share Button

Moving WordPress Installation to New Domain – SQL

A few database changes need to be done when moving WP from one domain to another; information below taken from a very  helpful article at My Digital Life:

To update WordPress options with the new blog location, use the following SQL command:

UPDATE wp_options SET option_value = replace(option_value, 'http://www.old-domain.com', 'http://www.new-domain.com') WHERE option_name = 'home' OR option_name = 'siteurl';

After that you will need to fix URLs of the WordPress posts and pages, which translated from post slug, and stored in database wp_posts table as guid field. The URL values in this field are stored as absolute URLs instead of relative URLs, so it needs to be changed with the following SQL query:

UPDATE wp_posts SET guid = replace(guid, 'http://www.old-domain.com','http://www.new-domain.com');

If you have linked internally within blog posts or pages with absolute URLs, these links will point to wrong locations after you move the blog location. Use the following SQL commands to fix all internal links to own blog in all WordPress posts and pages:

UPDATE wp_posts SET post_content = replace(post_content, 'http://www.old-domain.com', 'http://www.new-domain.com');

Share Button

Quickie – Disable WordPress Comments Temporarily

Very handy if you’re moving a WordPress blog during DNS  propagation time. This is best suited to remove the ability to comment on their blog without changing the comment status of posts in their database. See the alternative SQL method to turn off comments and pingbacks on a WP blog in hosting transition here.

From http://www.theblog.ca/wordpress-temporarily-disable-comments:

1) Turn off the display of the comment form in your Comments file in your template. To do this, go to “Presentation… Theme Editor…” then edit the Comments file.

You’ll see something like this.

<?php if ('open' == $post->comment_status) : ?>
 <h3 id="respond">Leave a Reply</h3>

Replace it with something like this:

<?php // if ('open' == $post->comment_status) : ?>
 <p>Comments are temporarily disabled</p>

Note: I see no need for the author’s suggestion of renaming the wp-comments-post.php file because we don’t need to worry about the spam comments accumulating during a hosting move.

Share Button

Moving WordPress With No Downtime: Resources

Helpful Technical Guides to Moving WordPress installations, and particularly Command Line/SSH instructions.

Step-by-Step SSH Guide
http://uncorrupted.net/technical-articles/move-wordpress-with-no-down-time/

WP Codex on Moving WordPress
http://codex.wordpress.org/Moving_WordPress

Moving WordPress via SSH
http://technosailor.com/2007/04/06/wordpress-faq-how-do-i-move-my-blog-to-a-new-host/

WordPress Installation via Command Line
http://guvnr.com/web/web-dev/wordpress-subversion/

Share Button

Testing Your Website on the New Web Host Before Switching Domain Records

From Uncorrupted Hosting Blog: ((Emphasis added.))

You can test everything by editing the hosts file on your PC

Go to: C:WindowsSystem32driversetc and open up the hosts file with a text editor, go to the end of the file and type the IP address of your new server, press tab & type your domain name, save the document, close your web browser, and clean your DNS cache (click start, click run type ipconfig /flushdns & press enter). Next, open your browser and go to your site – everything should work. When you’re done testing, delete the lines you added to your hosts file and then save/close it.

At this point, all that’s left to do is change the DNS servers for your site and point them at the DNS servers provided by your new host.

Using this approach, you can test a database driven site (like WordPress) on a new host before officiallygoing live at the new host. Always allow overlap between your old hosting account and new hosting account to make the move more seamless!

For my Mac friends, find your host files in the /etc folder. To access this file in Finder to to Go > Go To Folder, and type in /etc. ((Thanks to Mac Tips & Tricks for the info.))

When you’re done, delete that entry in your hosts file, and you’ll see what everyone else does when going to that domain.

Share Button