Mostly a reminder to myself, of what i need to do if i want to transfer a wordpress installation around.

Step #1: Backup

Make some form of backup of both your wordpress files and database. You can either do it manually or use some wordpress plugin for that. A nice plugin is XCLONER.

Manually its easy to make a .sh script and add:

mysqldump -u USERNAME -pPASSWORD DB_NAME > BACKUP.sql
zip -r BACKUP.ZIP WORDPRESS_DIRECTORY/

The first line backs up the database and the second one make a new zip file and adds everything under the WORDPRESS_DIRECTORY/ directory.

Replace the capitals to your liking.

Step #2: Download / Restore

Download the 2 files if you have made manual backup or use the plugin procedure to restore the files and the database.

Small fixes that make the difference.

Everything should be ok eh? Nope…

You may need to do another 3 steps:

Step #3: Change the settings to point to your new URL.

Quick and dirty way is to use SQL:

UPDATE wp_options SET option_value = replace(option_value, 'http://www.old-domain.com', 'http://www.new-domain.com') WHERE option_name = 'home' OR option_name = 'siteurl';

Step #4: Fix the internal links in posts

SQL again:

UPDATE wp_posts SET post_content = replace(post_content, 'http://www.old-domain.com', 'http://www.new-domain.com');

Step #5: htaccess change if you have moved the installation in a subdirectory (when moving to localhost typically)

In this case the .htaccess must include the subdirectory:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /SUBDIRECTORY/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /SUBDIRECTORY/index.php [L]
</IfModule>

# END WordPress

 Bonus 🙂

If you are experiencing problems after moving the site with google auth then try this:

delete from wp_options where option_name like 'ga_%'