Migrating WordPress
Here are a couple steps I follow each time I move a WordPress instance from one environment to another. I'll assume you're moving from Development to Production.
Database configuration
A migration usually involves changing the database configuration in wp-config.php.
Instead of having to modify the file every time, you could just modify wp-config.php to include something like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | if ($_SERVER['HTTP_HOST'] == 'dev') //could be 'localhost' or anything else { define('DB_NAME', 'dev_db_name'); define('DB_USER', 'dev_user'); define('DB_PASSWORD', 'dev_password'); define('DB_HOST', 'localhost'); define('DB_CHARSET', 'utf8'); define('DB_COLLATE', ''); } else { //production config: define('DB_NAME', 'prod_db_name'); define('DB_USER', 'prod_user'); define('DB_PASSWORD', 'prod_password'); define('DB_HOST', 'prod_server'); define('DB_CHARSET', 'utf8'); define('DB_COLLATE', ''); } |
That's one less thing to worry about.
Database Export and Clean-up
I like using PHPMyAdmin for quickly exporting and importing between databases. But regardless of what tool you use, WordPress stores the full URL in the database (something I find very annoying) so you'll also have to clean-up your database - these SQL commands have served me well:
1 2 3 4 5 6 7 8 9 10 11 | -- -- run after doing an import -- UPDATE wp_options SET option_value = REPLACE(option_value, 'http://dev_host', 'http://www.prod_domain') WHERE option_name = 'home' OR option_name = 'siteurl'; UPDATE wp_posts SET guid = REPLACE(guid, 'http://dev_host','http://www.prod_domain'); UPDATE wp_posts SET post_content = REPLACE(post_content, 'http://dev_host', 'http://www.prod_domain'); UPDATE wp_options SET option_value = REPLACE(option_value, 'http://dev_host', 'http://www.prod_domain'); |
.htaccess
Depending on how your development environment differs from production, you might also have to change your .htaccess file. You could of course just edit the file, but I find the easiest for me is to:
- Log into the WordPress admin (/wp-admin)
- Expand the Settings tab, then click on Permalinks
- Clicking on "Save changes" re-writes the .htaccess file
This is a tried and tested method I've been using a lot - but I'm curious to know how you do it. There might be some great plugins or tools that do all (or most) of this for you.
Stop WordPress from adding p and br tags
Even without the visual-editor, WordPress has a habit of adding <p> and <br/> tags
Add this to your templates/pages/whatever and it should take care of the problem.
<?php remove_filter('the_content', 'wpautop'); ?>
WordPress BlogInfo variables
bloginfo('atom_url'); //ATOM feed for site bloginfo('charset'); //The character set bloginfo('description'); //The description of the blog bloginfo('html_type'); //HTML version of the site bloginfo('name'); //Title of blog bloginfo('pingback_url'); //The pingback URL bloginfo('rss2_url'); //The RSS URL bloginfo('stylesheet_url'); //The URL for the template's CSS file bloginfo('template_url'); //The URL of the template bloginfo('url'); //The address of the blog bloginfo('version'); //Version of the WordPress installation bloginfo('wpurl'); //URL for WordPress installation
Highlight comments by Blog-author (WordPress)
If you'd like to distinguish your own comments from the comments of your visitors, here's how to highlight your comments with just a line of CSS - no extra plugins or unnecessary code.
1 2 3 | .bypostauthor { background-color:#PLACE_YOUR_COLOUR_HERE !important; } |
This works for WordPress versions 2.7+
WordPress 2.7 Beta 1
The new WordPress is ready for download.
The upgrade was easy enough and didn't break any of my plugins.
Apart from the new pretty dashboard-update, WordPress 2.7 simplifies future upgrades by giving you the option of doing it for you. I'll have to wait till the next release to try it out.
Download it here
Performing WordPress upgrades (Linux)
Note: Remember to always refer to the official upgrade guide. This is by no means official, but it has worked for me. I've tried to keep it as short and easy as possible.
Another Note: WordPress 2.7 comes out on November 10th. It will have an automatic updater module - so you probably won't have to worry about this kind of thing again after that!
Versions tested with:
- 2.6.3
- 2.6.2
- 2.6.1
- 2.6.0
Obtain the path to your wordpress installation, we'll assume it's
1 | /home/user/www/blog |
Safety first. Always.
So make a backup of your WordPress installation folder:
1 | cp -rp /home/user/www/blog /home/user/www/blog.backup |
Next, you'll want to make a backup of your MySQL database associated with it.
Refer to my Simple MySQL backup script to see how to do it.
You're good to go now - you'll be able to revert any changes you've made if you have to. (And that's a nice fuzzy feeling)
Let's get busy:
- Make an update directory to copy new files from
- Get latest WordPress zip file
- Unzip
1 2 3 4 | mkdir /home/user/www/blog/update cd /home/user/www/blog/update wget http://wordpress.org/latest.zip unzip latest.zip |
Just to keep things clear, we have 2 directories at this point:
New files:
/home/user/www/blog/update/wordpress
Original files:
/home/user/www/blog
Delete your old wp-includes and wp-admin directories (I rename them here, which has the same effect).
1 2 3 4 5 | mv wp-includes wp-includes.old mv wp-admin wp-admin.old mkdir wp-includes mkdir wp-admin |
Copy over the new files (NOTE that I haven't used the '-rp' flag for the last copy command):
1 2 3 4 5 | cp -rp /home/user/www/blog/update/wordpress/wp-includes/* ./wp-includes/ cp -rp /home/user/www/blog/update/wordpress/wp-admin/* ./wp-admin/ cp -rp /home/user/www/blog/update/wordpress/wp-content/* ./wp-content/ cp /home/user/www/blog/update/wordpress/*.php ./ |
Log-in to your admin-page. If WordPress needs to perform a database upgrade, it will do it for you.
Check that all your plugins are enabled and in proper working condition.
Optional: After you've tested everything and you're happy with the upgrade, you should delete all the extra files:
1 2 3 4 | rm -r /home/user/www/blog/wp-includes.old/ rm -r /home/user/www/blog/wp-admin.old/ rm -r /home/user/www/blog/update/ rm -r /home/user/www/blog.backup/ |
My top WordPress plug-ins
After secretly messing around with WordPress on one of my servers, I decided to move my blog to an instance of it permanently. Being a very flexible and extensible CMS, I've been researching some plug-ins for it. So far, I've come up with this list.
- Akismet - helps block spam (and it's really good at it too). Needs an API key that's obtainable from WordPress. Plus, it's free for personal use.
- Maintenance mode - adds a maintenance splash page. When activated only authenticated users and admins will be able to browse the site.
- Search meter - keeps track of what visitors are searching for
- Feedburner Feedsmith - redirects all RSS and ATOM feeds to a feedburner RSS feed instead
- Sociable - Adds links to Digg, De.li.cio.us, Stumble-upon and other sites for you
- WP-Cache 2.0 - A really efficient page caching system and effectively makes your site faster and more responsive
- WP-PageNavi - Adds a more advanced page navigation to the bottom of pages
- Subscribe to Comments - Allows users to get e-mail notifications for any subsequent comments made
- Smilies Themer - an easy way to change the default smilies pack
- Google Analytics for WordPress - You could just add the script, but this makes it easier.
- WP-Syntax - Add syntax highlighting to code-snippets (supports many languages)