2

I'm planning to buy a domain and install a WordPress site on it at a web-hosting company. But first I'll need to iron-out some bugs... I got a working LAMP-stack at my home-computer, so I'm thinking about first installing my site locally - off the Internet.

I'll be mostly tweaking and making "test-posts" to check that everything works, but I'll probably also make some posts I'd like to keep when I move the site and take it online.

When I'm done chasing bugs; I guess I'll just package the public_html|www directory-tree and upload it to the web-hosting company, and also export the database from my home-computer to the web-hosting.


What I'm wondering if there are some "best practices", some do-s and don't-s, some major pits to take note of?

For example, how can ensure the smooth transition of domain-name in posts and links as such, from localhost to whatever-i-end-up-buying.com (I know from previous attempt of running WordPress at my home computer, that this didn't always work quite well...).

2

Moving a WordPress website is fairly easy, here are the steps:

  • Backup your mysql database and re-import it in the new environment,
  • Move all the files to the new environment,
  • Update the wp-config.php file to reflect the new database connection information,
  • (*)Replace all occurrences of your domain name with the new one if it has changed

(*) This is the step that is confusing most of the time. People sometimes think it is enough to simply replace the few options in the database where the domain name appears but that is unfortunately not enough.

Indeed WordPress uses the PHP serialize/unserialize functions to store arrays in the the database. The problem here is that if you simply replace the domain name contained in a serialized object, you corrupt the data and will be unable to deserialize it because PHP serialization will add the length of every variable as part of the data. So unless you actually replace your domain name with another of the same size, you can not simply do a database search and replace.

Fortunately there are 2 easy solutions:

  1. This script: https://interconnectit.com/products/search-and-replace-for-wordpress-databases/ You simply deploy the folder in the root of your install and access it over http. Do not forget to delete the folder once you are finished
  2. This CLI: http://wp-cli.org/commands/search-replace/ Solution that I personally prefer because it does far more than just search & replace and can help you keeping a healthy WordPress instance.
1

Here are my notes that I use whenever moving a WP site from dev to test or to production:

At the current host/domain:

  1. Either gzip then download, or just download all the web folder content to your local computer.

  2. From SSH (e.g. Putty) session: Dump the database.

    $mysqldump -u username -p wp_databasename > mydump.sql

    (Alternatively, use phpmyadmin ‘export’ facility)

  3. Download the database dump to your local computer.

At the new host/domain:

  1. Create new database using SSH $mysql commands, or CPanel.

  2. Upload the database dump from step 2.

  3. From SSH session: Import the database dump into the new database.

    $mysql -u username -p wp_databasename < mydump.sql

    (Alternatively, use phpmyadmin ‘import’ facility)

  4. Upload the PHP utility “database search and replace” from interconnectit.com.

    (Note: this utility handles serialized data correctly)
    (Note: when uploading assure file permissions 644 folder 755)

  5. Run the search/replace utility and replace the prior site URL with the new URL.

  6. Upload the web folder content from step 1. Assure file permissions 644 and folder permissions 755.

  7. Update wp-config.php as needed (e.g. DB connection settings are probably different). Check .htaccess in case any localized items there to deal with, as well.

  8. Delete the “database search and replace” utility.

1

When I'm ready to migrate from my localhost to a live server and new domain, these are the steps that I take:

Preparing for

  1. Based on your profile, I going to assume that you know how to export your database on phpMyAdmin to prepare for migration
  2. While some people grab their entire WordPress directory, I prefer just the /wp-content/ folder and you'll see why in the next few steps
  3. Have a fresh install of WordPress set up on your live server
    • Nowadays, most hosting providers offer a one-click-install of the latest version of WordPress for you, saving you time with setting it up
  4. Get access to your new database and host

Migrating to new server

  1. With your fresh install of WordPress created on your new host, connect to it via FTP with a program such as FileZilla
  2. Delete the wp-content folder and drop in your localhost copy of the wp-content instead
    • Depending on how big your folder is, it may take a few minutes to transfer it all
  3. Go to your new database (via phpMyAdmin) and drop all of the tables that were initially created by the fresh install of WordPress and import your local copy instead

Updating to your new domain

While the migration is complete in terms of all of your files and data, this doesn't mane that it will be functional, because all of the links will be pointing to your localhost. Changing the home and siteurl values in your wp_options table (in your database) is not enough unfortunately.

You will still have your post and page content with your localhost URL (http://localhost/wordpress) causing your website to not display properly.

Once you've downloaded and imported your database to your localhost. Follow these steps:

  1. Go and download Interconnect IT's Database Search & Replace Script here
  2. Unzip the file and drop the folder where your WordPress is installed (the root) and rename the folder to replace (screenshot)
  3. Navigate to the new folder you created in your browser (ex: http://example.com/replace) and you will see the search/replace tool
  4. It should be pretty self-explanatory up to this point: enter your localhost URL in the search for… field and the new URL in the replace with… field

You can click the dry run button under actions to see what it will be replacing before you execute the script. Once you're done be sure to remove the /replace/ folder. Check your website to make sure nothing else is out of place and you should be good to go.

-1

I always use the popular plugin "Duplicator" (in WP Plugin Directory).

Never had any problems with it. Install, create an archive. You'll receive a .ZIP file with all of your contents and a installer.php file. Upload both to your server and access the installer.php. Follow the install wizard and have fun. Works like a charm and it is really user-friendly.

The installer script takes care of all data, putting it in your ne empty database, changing the the URL in the database, changing the wp-config.php file etc...

After the migration, log into your wordpress and save your permalinks to activate the rewrite. That's it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.