Thursday, January 21, 2010

How to transfer wordpress site to new domain or new location - Way 1

Wordpress stores two address urls inside the database.
One address url determines the location of your blog files.
Another address url determines the location of main index.
If you do default install then both blog address and main index urls will be same.

There are two reasons when you need to change one of the two address urls.

1) You want to change the wordpress url or blog url or you have tried to change the Blog URL or WordPress URL in Settings, and an error has occurred.

2) You want to move/copy your wordpress site to a new domain/new hosting server.

Following is the step by steps procedure about how to transfer wordpress site to new domain or new location.

Step 01: Backup/Export full database from your old wordpress site.
Note that this step is not required if you want to move/transfer your wordpress site in your same hosting provider cpanel even if you want to move to a new domain in the same hosting server. This step is only required if you want to transfer your wordpress site to a new hosting server or if you want to copy wordpress site across your new domain.

You can use command line tool and any GUI tool to backup database. If you use command line mysqldump tool then you can issue following command, to export a mysql database - named wordpress_01 where username is root and password is prema and dumpfile name is d:\dump.sql

E:\>mysqldump -u root -pprema wordpress_01 >d:\dump.sql

If you use phpmyadmin GUI browser then you can do:
- Login to phpmyadmin
- From the left side click on your desired database that you want to export.
- Database Structure is displayed. Click on Export tab.
- Select all the tables and select radio button as SQL (though these two are selected by default)
- You can choose Compression to None or "zipped" or "gzipped". And then click Go.
- You have now your wordpress database backup.

Step 02: Create a new Wordpress database in the new hosting server.
Note that this step is not required if you want to move/transfer your wordpress site in your same hosting provider cpanel even if you want to move to a new domain in the same hosting server. This step is only required if you want to transfer your wordpress site to a new hosting server or if you want to copy wordpress site across your new domain.

You can use command line tool and any GUI tool to create a new wordpress database in the hosting server where you want to copy wordpress site or transfer wordpress site.
To create a new mysql database named wordpress_new using command line tool issue following command after login as admin user,
mysql> create database wordpress_new;
Or you can use your cpanel to create new mysql database. After login to cpanel click on the MySQL Databases and then create database.

After you create new database,
- Add New User. Create a new username and password. It is easy in cpanel. If you are good at command line interface have a look at Create user in mysql.

- After you create user assign the user to the new database created.

Step 03: Download and upload (Transfer/Copy/Move) all WordPress files & folders to new site:
Copy/Move/Transfer whole wordpress directory from your old site to your new site. You can use any ftp tool to do that for example FileZilla Ftp Client. If you have ssh access to your server you can scp/cp files from your old site to your new site. Note that you must transfer whole wordpress site so it should include your theme files, template files, plugin files.

Step 04: Modify file wp-config.php:
If you open wp-config.php file you will see lines like,
/** The name of the database for WordPress */
define('DB_NAME', 'mysql_arju');
/** MySQL database username */
define('DB_USER', 'mysql_arju');
/** MySQL database password */
define('DB_PASSWORD', 'arju');
/** MySQL hostname */
define('DB_HOST', 'localhost');

Now change these values of mysql database, username and password to accommodate values for new site mysql database. In this example, it should be
define('DB_NAME', 'wordpress_new');
define('DB_USER', 'arju');
define('DB_PASSWORD', 'test');

Note that above change of DB_NAME, DB_USER, DB_PASSWORD is not required if you want to transfer site in the same server or if you want new server but there you have database, username, password with the same name as it was in old site.

Adding the following lines are extremely important if you like to change your domain name or to change your wordpress/blog location in the same domain.

define('WP_HOME','http://arju-on-it.com');
define('WP_SITEURL','http://arju-on-it.com');


where http://arju-on-it.com will be the new address url for my both wordpress home and blog site.

Step 05: Import (upload) the previously backup database.
Note that this step is not required if you want to move/transfer your wordpress site in your same hosting provider cpanel even if you want to move to a new domain in the same hosting server. This step is only required if you want to transfer your wordpress site to a new hosting server or if you want to copy wordpress site across your new domain.
Using command line tool or using graphical user interface you can import the previous exported database.
If you use phpmyadmin then just select your database, click the Import tab, click Choose file button and choose the sql file that you exported previously (if you have gzipped/zipped version then you need to unzip it) and then click Go. You can check list of tables imported into database.
If you use command tool then you can use mysqlimport tool to load tables from the sql files into mysql database.

Step 06: Change the Urls in the database wp_options and wp_posts tables:
You need to change url addresses from database to adapt the urls of new domain/new location.

To fix URLs of the WordPress posts and pages issue,

UPDATE wp_posts SET guid = REPLACE (guid,'http://old_site_url.com','http://new_site_url.com');

If you have linked internally within blog posts or pages with absolute URLs, these links will point to wrong locations after you move your site. 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_site_url.com', 'http://www.new_site_url.com');

Update WordPress options with the new site url, by using following SQL command:

UPDATE wp_options SET option_value = replace(option_value, 'http://www.old_site_url.com', 'http://www.new_site_url.com') WHERE option_name = 'home' OR option_name = 'siteurl';

2 comments: