How to successfuly move a WordPress blog from one location (url/server) to another (LAMPP installation). This includes, making a complete backup of the filesystem and database, creating a new database and a user for your blog, and finally change settings and content to apply to your new installation. Installing the OS, web server software and so on is not in the scope.
Backup current installation
The first thing you have to do is make a complete backup of your current WordPress installation from the filesystem. Navigate to your wordpress installation directory and compress the whole thing to a single tar.gz file. If your installation is in /var/www/wordpress, navigate to /var/www/ and compress the entire wordpress directory.
cd /var/www/ tar zcvf wordpressbackup.tar.gz wordpress/
Now you have one file containing all your themes, plugins, pictures, uploads and so on, but for the blog to have any content after moving we have to make a backup of the existing database as well. This is done by running the following command, which dumps the entire database to the file wordpressDump.sql. Enter the root password for your mysql database when prompted: (wordpress is the name of my database)
mysqldump -u root -p wordpress > wordpressDump.sql
The wordpressDump.sql now contains all your posts, pages, users, comments and blog settings, and with this done the backup is complete. It is now time to move the wordpressbackup.tar.gz and the wordpressDump.sql file to the new installation.
After copying the the files to the new location. Extract the wordpressbackup.tar.gz. You may ned super user privileges(I use /var/www again, and install wordpress at the document root of the new server.)
cd /var/www/ tar zxvf /path/to/backupfile/wordpressbackup.tar.gz
Through out this tutorial when it comes to url’s later on I will use http://oldsiteurl/wordpress and http://newsiteurl/wordpress as references to the two sites.
Create new database with a user for wordpress
For this tutorial I am gonna create a database and user both called wordpress. The easiest method is to use the same names as in the old installation. If that is not possible or if you wish to change them remember to change the database settings in your wp-config.php to match the changes you make here.
Creating a new database in mysql is done with the create database command. Log in to mysql as root and create your wordpress database.
mysql -u root -p mysql> create database wordpress;
Creating a user is just as simple, but now we also have to grant the user access to the wordpress database.
mysql> CREATE USER 'wordpress'@'localhost' IDENTIFIED BY 'your-password'; mysql> GRANT CREATE, SELECT,INSERT,UPDATE,DELETE ON wordpress.* TO 'wordpress'@'localhost'; mysql> commit; mysql> FLUSH PRIVILEGES; mysql> quit
Import and modify the database backup for the new installation
Import your wordpressDump.sql into the new wordpress database like this. (wordpress is the database name). We have to do this as root beacause when we created the wordpressDump.sql file mysql added a line thats drops tables if they exists, and as you see from the GRANT statment above our wordpress user does not have drop privileges.
mysql wordpress -u root -p < wordpressDump.sql
Ok, so now we are done moving all your data. This was all very straight forward. Now we must modify the records in the database to reflect the changes in your blogs url as a result of the moving. The first two we have to change are the siteurl and home settings in the wp_options table. (The table name may not be wp_options, It could have some other prefix or maybe no prefix at all. The wp prefix is the default. To check your table names, log in your wordpress database and type
mysql wordpress -u wordpress -p mysql> update wp_options set option_value = 'http://newsiteurl/wordpress' where option_name='siteurl'; mysql> update wp_options set option_value = 'http://newsiteurl/wordpress' where option_name='home'; mysql>commit;
The next step is to change all the links to and in your posts. Luckily mysql has a very nice replace command which is excellent for this.
mysql> UPDATE `wp_posts` SET `guid` = REPLACE(`guid`,"oldsiteurl","newsiteurl"); mysql> UPDATE `wp_posts` SET `post_content` = REPLACE(`post_content`,"oldsiteurl","newsiteurl"); mysql> commit; mysql> quit
If you now start a browser and navigate to your new site url your blog should appear just as it did before.
If you're new system is running Ubuntu and you get a problem when using permalinks you probably have to enable the mod_rewrite module for Apache. The rewrite module is disabled by default on Ubuntu.
sudo a2enmod rewrite
You will also have to edit /etc/apache2/sites-available/default and set
on both the / and /var/www directories.
A tip at the end:
As of version 2.6 WordPress introduced revisions as a extra safety feature. It's probably a nice feature, but it kind of fills up your database and I don't like that. To clean out the revisions Andrei Neculau has put together this beauty of a sql query which also takes care of post meta and post terms.
DELETE a,b,c FROM wp_posts a LEFT JOIN wp_term_relationships b ON (a.ID = b.object_id) LEFT JOIN wp_postmeta c ON (a.ID = c.post_id) WHERE a.post_type = 'revision'
To completely turn off the revision feature you have to edit your wp-config.php and enter this line:
define ('WP_POST_REVISIONS', 0);