.

Video How-to: 10 Tips To Make WordPress Hack-Proof

Video How-to: 10 Tips To Make WordPress Hack-Proof

Olly 'the_guv' Connelly's book cover: WordPress 3 Ultimate Security

UPDATE: June 2011.

Inspired by this popular post, guv’s WordPress 3 Ultimate Security, the first-ever book explaining in detail how to secure the popular blogging and content management platform, has been released. Here’s the detail:-

Having your blog hacked isn’t fun, and the standard WordPress installation is not impermeable. Not only does a hacked blog result in downtime, while you work with your ISP to track the problem and ensure it doesn’t happen again, it can also mean you spend time, for instance, getting your email client resolving properly once more. All in all, valuable time wasted.

Prevention is better than cure. Here are 10 Tips To Make WordPress Hack-Proof.

What You Need

Before You Begin

  • backup your files, using your ftp client
  • backup your database, using wp-phpmyadmin. If you don’t know how to do that, check this out this video tutorial, here at Guvnr.

Video: [cf]videoTitle[/cf]

Watch the, er, guvideo for a better idea of how to do this.

Check out the_guv's YouTube channel at http://youtube.com/guvnrDOTcom

...or if you can't be bothered with that, or even if you can, here's the detail...

1. Upgrade WordPress. To the latest version. If you’re using 2.7 or later, this can be done from your admin dashboard, at the click of a button, automatically. Just look for the “upgrade” button. If you’re using an earlier version, read this.

2. Update Plugins. Make sure all are upgraded to their latest versions. If they’re not, you are notified on your plugins admin page. Old versions can present a security risk.

10 Tips To Make WordPress Hack-Proof image

3. Change “wp_” Database Table Prefix. I used to use wp-security-scan, from Semper Fi Web Design but I DO NOT CURRENTLY RECOMMEND IT because it throws errors with WordPress 3+. I cannot find a reliable alternative plugin but here’s a method that works every time (just be careful, don’t do this when you’ve had a beer!):-

  • i. Deactivate all WordPress plugins, as a precaution.
  • ii. Backup the database, as explained in Guvnr’s video tutorial.
  • iii. Open the downloaded *.sql file with a text editor (where * is the name of your database.)
  • iv. Find and replace all instances of your “wp_” prefix with your new prefix.
  • v. Within your WordPress database, drop all the tables. DO NOT DROP THE DATABASE itself, only the tables. wp-phpmyadmin is a great plugin to use.
  • vi. Still within your WordPress database, import your newly-amended *.sql file, the one you edited by changing the prefix. wp-phpmyadmin or similar again.
  • vii. Open and edit your wp-config.php file, in the root blog folder, changing the “$table_prefix = ‘wp_’;” to “$table_prefix = ’yourNewPrefix_’;”.
  • viii. Reactivate your plugins.

4. Delete “Admin” User. Just to make hackers work harder, bin this. Create a new user with administration rights, and give the user a nickname (for public display) that is not the same as the username. Then log out, log back in as the new user, and delete the original “admin” user.

5. Use a Stronger Password. Bit obvious, this one. Mix it up with letters, digits and special characters, upper and lower case. I use RoboForm to remember (and encrypt) my passwords, and that’s free.

6. Hide your WordPress version. From your theme’s folder, open “header.php”, search for the line…

<meta name=”generator” 
content=”WordPress ” />

…and delete it. It has no useful purpose.

7. Ensure WordPress Database Errors Are Turned Off. In recent WordPress versions, they are turned off by default. So upgrade.

8. Remove WP ID META Tag. Delete this tag from the WordPress core. After you activate and run wp-security-scan, this is done automatically.

9. Create an .htaccess File in “wp-admin/” Open a new text file and paste this…

    # BEGIN WordPress
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    # END WordPress

… Save the file as .htaccess and upload it to your “wp-admin/” folder, ie, to http://myblog.com/wp-admin/

10. Hide Your Plugins. If you’re not sure whether they’re hidden or not, navigate to http://myblog.com/wp-content/plugins. If you see a 404 error page, they’re hidden. Otherwise, you’ll see them listed. In that case, copy the following into a new .htaccess file, adding the file to your wp-content/ folder…

    # BEGIN WordPress
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    # Prevents directory listing
    IndexIgnore *
    # END WordPress

Some web hosts don’t allow you to administer .htaccess files. If that’s the case, instead of using an .htaccess file to hide the list of plugins, create an index.html file. You can write something about restricted access in there, if you like. Either way, this file will prevent a plugin listing.

Now navigate to http://myblog.com/wp-content/plugins. They should be hidden.

After You’re Done

Just to be thorough, and because a few things have changed…

  • Backup your files again, using your ftp client.
  • Backup your database again, using wp-phpmyadmin.

That’s it. Your blog is more secure, and way less hackable. Go make content!

.