This howto will explain how to move WordPress from one domain or server to another with about 5 minutes worth of work.
Applicable to Centos Versions:
- Centos 5.x
- Centos 6.x
Explanation of requirements.
- Admin or root access to the old or existing website, database, database dump and files.
- Admin or root access to the new server.
- A basic understanding of Linux, Apache httpd, Mysql and WordPress.
Doing the Work
This howto assumes your domain name already resolves to the new server and you’ve already uploaded the core WordPress files, custom themes and any plugins in to the proper httpd docroot.
- Take a mysqldump of the database to be moved and save it locally.
- Change the old WordPress Address (URL) and Site Address (URL) in the database using sed.
- Copy the document root of the site
- Or, from the WordPress admin, with an admin account, use the following plugin from the WordPress plugins repository:
- Edit wp-config.php
<b style="color: green;">mysqldump -u root -pmypass mydatabase > example_db.sql</b>
replace "mypass" with your password, no spaces between your password and the -p
<b style="color: green;">sed -i 's/example1.com/example2.net/g' example_wpdb.sql</b>
In this example we're replacing any occurance of "exmaple1.com" with "example2.net" in the example_wpdb.sql database.
a. Create a new empty mysql database with the same name as the one you're importing on the target server.
b. Import this new, edited database on the new target server.
These are the files and directories you'll need:
<b style="color: green;">
zio or tar these files up and copy them to your local computer.
This plugin automatically creates a zip file of the above steps for you to download within the wp-admin area, though you will still need to import the database to the new server.
Add this on a separate line by itself near the end of the wp-config.php file after all the other "define" statements:
<b style="color: green;">define('RELOCATE',true);</b>
a. Save and upload wp-config.php to the new server.
b. Load the site at /wp-login.php directly, login to the wp-admin --> http://newsite.com/wp-login.php
c. Go to: settings --> general and make sure the addresses are correct.
d. Again, edit the wp-config.php and remove completely or comment out the previously added define statement like this:
<b style="color: green;">/*define('RELOCATE',true);*/</b>
If you've made the site correctly using relative links for resources and images then no further action should be required and the site should function normally.
If not, then you'll need to use a search and replace utility or something like the Linux command sed to find all instances of the previous root domain and change it to the new domain.
It wouldn't matter what platform you used or even if you used static files for each page, if you're developing a site you should always use relative links for internal resources, otherwise you will have to find/replace every time you move a site.
Troubleshooting / How To Test
Explanation troubleshooting basics and expectations.
- Take a good look at the steps above and make sure you’ve followed them in precise order.
Stop where things stop working as expected and take note of any error or unexpected output or behaviors so you can provide them for others helping you.
Also be prepared to disable any plugins or non-default Wordpress themes for testing, this is a fundamental process to debugging Wordpress issues.
Also make sure to be prepared with your:
Common problems and fixes
We test this stuff on our own machines, really we do. But you may run into problems, if you do, come to #centoshelp or #wordpress on irc.freenode.net