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
Requirements
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
1 2 |
<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 |
1 2 3 4 |
<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. |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
These are the files and directories you'll need: <b style="color: green;"> index.php license.txt readme.html wp-activate.php wp-admin wp-blog-header.php wp-comments-post.php wp-config-sample.php wp-content wp-cron.php wp-includes wp-links-opml.php wp-load.php wp-login.php wp-mail.php wp-settings.php wp-signup.php wp-trackback.php xmlrpc.php </b> zio or tar these files up and copy them to your local computer. |
1 2 |
<a href="http://wordpress.org/plugins/simple-backup/">http://wordpress.org/plugins/simple-backup/</a> 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. |
1 2 3 4 5 6 7 8 9 10 11 12 13 |
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.
1 2 3 4 5 6 7 8 9 10 11 |
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. <b><em>Important</em></b> 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: Wordpress version Linux version httpd(Apache) version php version MySQL version |
Common problems and fixes
Disclaimer
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
Added Reading
Last Modified: 22 Apr, 2020 at 16:46:29