Bummer! This is just a preview. You need to be signed in with a Basic account to view the entire video.
Migrating the Database5:16 with Alena Holligan
All of the content that's entered via the control panel is stored in the database. When you upload and download files using FTP you don't transfer the information that's stored in the database. We'll be using PHPMyAdmin to transfer the database manually so that you understand what is going on behind the scenes and are able to troubleshoot if something goes wrong. There are also many plugin options you can use.
Notes on FTP
FTP stands for File Transfer Protocol. Most hosting providers also allow for SFTP which is a SECURE File Transfer Protocol. If your hosting company supports this option, it is the better choice.
For more information, you can view the course to Upload the Website
UPDATE wp_options SET option_value = replace(option_value, 'http://www.oldurl', 'http://www.newurl') WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE wp_posts SET guid = replace(guid, 'http://www.oldurl','http://www.newurl');
UPDATE wp_posts SET post_content = replace(post_content, 'http://www.oldurl', 'http://www.newurl');
UPDATE wp_postmeta SET meta_value = replace(meta_value,'http://www.oldurl','http://www.newurl');
Word of Caution and Plugins for Updating URLs
Some plugins may place URLs in other places in the database. If you do a search and replace on your entire database to change the URLs, you can cause issues with data serialization, due to the fact that some themes and widgets store values with the length of your URL marked. When this changes, things break. To avoid that serialization issue, you have four options:
- Use the Velvet Blues Update URLs plugin if you can access your WP Admin Dashboard.
- Use the Better Search Replace plugin if you can access your WP Admin Dashboard.
- Use WP-CLI's search-replace if your hosting provider (or you) have installed WP-CLI.
- Use the Search and Replace for WordPress Databases Script to safely change all instances on your old domain or path to your new one. (** only use this option if you are comfortable with database administration ** )
Backup and Migration Plugins
Here are some plugins you may wish to try.
You want to start in phpMyAdmin on your development environment.
As long as you have access to phpMyAdmin,
it doesn't matter where your environment is hosted.
You can follow the same steps.
In phpMyAdmin, choose the development database.
Along the top, we'll click to Export.
We'll do a Custom export with everything selected and Save output to a file.
We also want to make sure that we add drop table.
When we click Go, we should now have our database successfully backed up.
Take note of the table prefix.
It's easiest if the table prefix for your development and
production environments both match.
If you have a fresh installed WordPress on your production environment,
this may not be the case.
I'm going to change my production environment to match my development
In wpconfig.php, we'll find a table prefix.
I'm going to change this to localwp.
Now, we can come in to phpMyAdmin on our hosted production server, and
choose our production database Since the prefix was not correct,
I'm going to drop all the tables in this database first.
We can then import the file that we've just exported from my local development.
We should now see all of our database information
successfully stored on our production server.
Let's take a look at the production site.
Now it's quite possible that you continue to work on your local server,
maybe editing your theme, or a plugin, or some other part of the site.
Before you start developing on your local site, you may want pull down the freshest
database from the production server by exporting the production database.
You would then import that data to the local database.
Export from the database you wish to keep, and
import the database you wish to override.
Be extremely careful when updating your database, or
you can easily override the wrong data.
You can always download a copy of any database for backup.
Although we're technically set up now, there's one final step that you should do.
And that's to run a search and replace on the database for the URL.
This will change all the hard coded URL references.
This is particularly helpful if you have images on your site,
since some of those images may still be pointing to the old file location.
We haven't made any updates to the URLs to reflect the change in the site
within the database itself, only the configuration file.
I'm going to run a couple SQL commands that I'll add to the teacher's notes.
You can also update these URLs using a search and replace plugin.
On our production server, we'll go to SQL.
We're going to update the local WP options, and
we'll replace our old URL with a new URL,
where option name equals home or option name equals site URL.
Next, we'll update the post, again, setting our old URL to our new URL.
One more update for our post.
And then we can also update the post meta.
Great, all the URLs for our images and
anything else should be updated in the database.
I wanted to show you how to migrate WordPress manually, so
that you understand the different parts of a WordPress site, and
be able to troubleshoot if something goes wrong.
However, remember that all of the content that's entered
via the WordPress dashboard is stored in the database.
And when you upload and download files using FTP,
you don't necessarily transfer all the information that's stored in a database.
You do not always have to transfer a site manually.
There are many different plugins that allow you to both back up and
migrate part or all of your WordPress site.
I've included links in the teacher's notes for some plugins that you may wish to try.
Some of them include a free version, which is limited in the capabilities,
while also including a pro version that costs money.
You need to sign up for Treehouse in order to download course files.Sign up