Posts Tagged Unix Hosting
Moving a WordPress Install to Another Domain
Posted by Dave Jesch in WordPress Tech on September 13, 2010
I’ve been asked a number of times how to move a WordPress install from one domain to another. The reason this creates some problems is that WordPress puts the domain name in the “options” table, as well as references to images within the content when creating Posts and Pages. To move a domain, therefore, requires you to adjust these references as well as the WordPress options.
To address this, I’ve outlines the following steps that you can take to move a WordPress install:
-
Backup Your Database
This can be done a couple different ways. If you have access to phpMyAdmin, you can use the Export tool provided there. If not, then you can install a free plugin called “WP-DBManager” or “WordPress Database Backup.” Either one of these tools will allow you to create a backup of your database.
-
Make a Copy of Your Files
You will need to move all of the files for the WordPress install, as well as your uploaded content stored in the wp-content/ directory. You can use an FTP tool for this.
-
Upload Files to New Domain
Now upload the files you copied in Step 2 to your new domain. If your original WordPress install was in a subdirectory, you should try to upload your new install to a similar directory. If you’re changing directories, pay attention in the Step 6 instructions.
-
Create Database on New Domain
A new database will have to be created on your new domain. Most hosting companies provide simple tools to do this. Create a database and make sure you record the name, user, password and host so that your configuration settings can be changed in Step 7.
-
Upload Database Contents
You need to import the database backup that you made in Step 1 into your database on your new domain. The easiest way to do this is using phpMyAdmin, which most hosting companies provide. Use the “Import” tool and upload the database backup. You can also do this with Unix commands and SSH access, but that’s a bit advanced for most people. So for now, we’ll just go with the phpMyAdmin tool. Just know that if your host does not have phpMyAdmin available that there are solutions.
-
Modify Database Contents
As mentioned above, WordPress stores the domain name as part of its configuration. Now that you’re on a new domain, you need to change that configuration. You can’t do this within WordPress because WordPress isn’t working on your new domain yet. There are two ways of doing this. First, you can edit the SQL file before you upload it in Step 5. I don’t recommend this unless you are comfortable using a text editor (a Word Processor won’t work for this) and at least somewhat familiar with SQL. The other way is by executing a few SQL commands. Using phpMyAdmin again (or command line tools in case you don’t have phpMyAdmin available), you can run these commands:
UPDATE wp_options SET option_value = REPLACE(option_value, 'www.olddomain.com', 'www.newdomain.com'); UPDATE wp_postmeta SET meta_value = REPLACE(meta_value, 'www.olddomain.com', 'www.newdomain.com'); UPDATE wp_posts SET post_content = REPLACE(post_content, 'www.olddomain.com', 'www.newdomain.com'); UPDATE wp_posts SET guid = REPLACE(guid, 'www.olddomain.com', 'www.newdomain.com');
If you have a BuddyPress install, you will also want to run these two commands:
UPDATE wp_bp_activity SET action = REPLACE(action, 'www.olddomain.com', 'www.newdomain.com'); UPDATE wp_bp_activity SET primary_link = REPLACE(primary_link, 'www.olddomain.com', 'www.newdomain.com');
This makes a couple of assumptions. First, the database prefix wp_ may be different for your install. You can check the contents of your wp-config.php file if this is different. Second, if you installed WordPress in a subdirectory, that subdirectory will need to be included as part of your domain name. So where you see ‘www.olddomain.com’ use ‘www.olddomain.com/wpdirectory’ and similarly ‘www.newdomain.com/wpdirectory’ for the new domain.
-
Change Database Configuration
Most hosts have slightly different naming that they use for databases. They also may be using a different host name for the database server, not to mention passwords. When moving a WordPress install between domains and especially between hosts, you will probably have to change your database configuration settings. Edit the wp-config.php file on the new domain and look for the following settings:
/** The name of the database for WordPress */ define('DB_NAME', '{{your database name here}}'); /** MySQL database username */ define('DB_USER', '{{your database user name here}}'); /** MySQL database password */ define('DB_PASSWORD', '{{your database password here}}'); /** MySQL hostname */ define('DB_HOST', '{{your database host name here}}');Where you see the phrases within the {{double braces}}, these are the places that you will potentially need to make changes. Use the names and passwords that you recorded while performing Step 4.
-
Redirecting Traffic
The last step you may want to perform is to redirect the traffic from your old domain name to the new one. This depends largely on your host and/or domain manager. Most managers allow you to set up a forward to another domain. However, if your old WordPress install was in a subdirectory redirecting all domain traffic may not be an option. There is a way to do this using .htaccess. You can contact me for help with this if you’re unfamiliar with doing this in Apache.
Moving a WordPress install to a new domain name may look like complex wizardry, but it’s not that bad. It shouldn’t be done by someone who is not comfortable with the basic tools involved: an FTP client and phpMyAdmin (or the command line tool equivalents), but it is a fairly straightforward process.
Moving a BuddyPress or a WordPress MultiSite install is another matter. There are more databases that need to be updated and a few more configuration settings. It’s still possible though, and I’ve written some scripts to help me with the process.
WordPress Security Using .htaccess
Posted by Dave Jesch in WordPress on December 24, 2009
In a way, WordPress is a double-edged sword. On the one hand, it’s ease of use and popularity make it a great choice when starting a blog and building a web site. But this same popularity means that it is a huge target for hacking. For this reason alone, security should be taken seriously.
If you’re using a hosting service that runs on Unix, one way you can increase the security of your web site is by using an .htaccess file. This file is used by the web server itself in processing requests and can be programmed to re-route the request if needed.
Here’s an example of a .htaccess file that can block a couple of common script attacks:
Options +FollowSymLinks
RewriteEngine On
# if your blog is not installed in root, uncomment and change the
# following line to the directory that WordPress is installed in:
# RewriteBase /
RewriteCond %{QUERY_STRING} (\<|%3C).*script.*(\>|%3E) [NC,OR]
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
RewriteRule ^(.*)$ index.php [F,L]
There may already be a .htaccess file on your host, so adding the RewriteCond and RewriteRule commands after the last RewriteRule and before the would be all that’s necessary.
What this does is block three different types of attacks.
The first looks for a <script> tag in the query string. This is used to inject JavaScript into a request.
The second checks to see if a global variable is attempting to be set.
The third is checking to see if someone is attempting to reset one of the global request variables.
WordPress should already be blocking these, but using multiple methods of security doesn’t hurt. And doing this at the web server level, as well as the code level, gives you multiple layers of protection.