How To BackUp Your WordPress Database to LocalHost

How-To-Backup-Wordpress-Localhost

I needed to find out today how to backup my wordpress database from my server to localhost on my laptop. I have been using XAMPP for a long time now to create a server on my laptop so that I can play with and test wordpress websites without being ‘live’ on the internet. I usually end up breaking the wordpress websites or mess things up by tweaking with theme codes or playing with the database in phpmyadmin.

Recently I had a problem where I could log into the dashboard of my test wordpress website on my laptop localhost server, but couldn’t see the XAMPP localhost website pages or posts on my browser. It turned out a very, very simple error on my side was the problem (I’ll explain later). However this problem made me think I had broke the database so I needed to reinstall it. Now I needed to find out more on how to backup a wordpress website database from the hosting server to the localhost server on my PC. I want to share what I learnt on Google today with you :)

How To Backup a WordPress Database

I am going to show you the information I learnt from a variety of other websites. One of the best places to start is web developer Ivan Kristianto’s website. Thanks Ivan!

PHPmyAdmin Database BackUp Steps

First thing is to backup your database. I did this using phpmyadmin as recommended by WordPress.

  1. Log into your hosting phpmyadmin (I used Cpanel from my hosting company to go to PHPmyAdmin)
  2. Click on the database needed in PHPmyAdmin
  3. Click Export tab
  4. Follow WordPress example for boxes to click
  5. Save File As – I choose “gzipped” helps with larger databases
  6. Saved file to desktop looked like “example_database.sql.gz”

WordPress Files BackUp Steps

The second thing I did, as Ivan recommended, was to download the WordPress files from my hosting server.  Again I used Cpanel to achieve this.

  1. Log into Cpanel on your domain (Hosting companies usually send you the details in your signup email with them)
  2. Go to File Manager
  3. Click the folder with your wordpress website e.g “public_html” or “httpdocs”
  4. Click the compress button on top right
  5. I chose the “Gzip Tar Archive” option to save as
  6. Then find the file “example.co.za.tar.gz” and click download
  7. Save to your computer where you want. (I choose desktop)

Add Downloaded WordPress Files To LocalHost Steps

Now you have your downloaded wordpress database and files from your hosting server time to put them on your PC’s localhost.

  1. Extract the wordpress file “example.tar.gz” using software like 7Zip (freeware) or other recommended by gzip.org
  2. The file becomes a .tar file which you can extract again using 7zip
  3. Now you can see a folder with all your wordpress stuff, like wp-admin, and lots of other folders and files
  4. Add all these folders and files to a newly created folder in your XAMPP localhost htdocs folder. (mine was called “test”)

Add Downloaded WordPress Database to LocalHost PHPmyAdmin

Now you have to add the websites database you downloaded in the beginning to the XAMPP localhost phpmyadmin.

  1. I logged in using http://localhost/phpmyadmin/index.php
  2. Then used the create a new database section to make my database called “test”
  3. Then clicked import tab whilst in my database called “test’
  4. Browsed for my database file called “example_database.sql.gz” on my desktop
  5. Clicked “Go” in bottom right corner
  6. Now I could see all the database tables loaded on the left
  7. Clicked “wp_options” table in the database on the left
  8. Changed the option name “siteurl” from the website address to http://localhost/test
  9. Changed the option name “home” from the website address to http://localhost/test

Get LocalHost WordPress Files to Work With LocalHost Database

Now I need my downloaded wordpress folders and files to work with my downloaded wordpress database.

  1. Go to htdocs in XAMPP localhost on your PC
  2. I clicked my folder “test”
  3. Found the wp-config.php file
  4. Opened using notepad
  5. Changed the existing DB_Name to “test”
  6. Changed the existing DB_User to “root”
  7. Changed the existing DB_Password to “”
  8. Saved the wp-config.php file.

My Internet Worpdress Website Now on Localhost

If all has gone well you should be able to log in to your wordpress website on your own PC’s localhost without the internet.

  1. I went to http://localhost/test/wp-admin/
  2. Logged into to the wordpress dashboard using the exact username and password as needed for the internet website
  3. Able to see the same wordpress dashboard with all my posts and settings from the internet version of my website
  4. See your website at http://localhost/test

Where I Went Wrong

In the beginning I mentioned my original problem was that:

I couldn’t see the XAMPP localhost website pages or posts on my browser

This is a basic mistake I forgot to do. CHANGE THE PRETTY PERMALINKS TO DEFAULT

That was it! So please don’t get frustrated wondering why you can log in to your XAMPP localhost wordpress website, see the front page of the website at http://localhost/test but then not see any of the posts or pages when you click on them cos you forgot to change the permalink setting like me.

WordPress BackUp Plugins

I know there are wordpress plugins to backup your database with one click like:

I would recommend these as they are very simple and important.

However, I have had problems with these wordpress database backup plugins on certain hosting servers because of the way the servers are setup. So I now I at least know how to backup manually and how these plugins work.

My Bonus Localhost WordPress Plugin Find

In my whole learning mission with this backup saga I found a great make your life easier wordpress plugin when using XAMPP localhost wordpress websites.

The wordpress plugin is called “No Login” by Ozh

This wordpress plugin means you do not have to remember or type in your username and password on the XAMPP localhost wordpress website anymore :)

When I go to http://localhost/test/wp-admin/ I am automatically logged into my wordpress dashboard. It saves time and frustration if you forget your username or password.

Download No Login by Ozh from the official wordpress.org website or just search for “No Login” in the add plugin section of your wordpress dashboard.

My Helpful How To Backup Saga Websites

Here is my recommended reading. These are the website pages that helped me alot with my original Google search question of “How to backup up your wordpress database to localhost