(WordPress) How I Transfer Custom WordPress Theme with Database from Live Server to Local Environment

Kenta Kodashima
3 min readApr 5, 2019

In this article, I will summarize how I transfer WordPress from the live server to the local environment including the database.

Note: Make sure to back up everything if you try the same thing.

0. Expected Case & Preconditions

Expected Case

  • Already developed a WordPress them on the local environment
  • Already deployed the theme to the live server
  • Want to transfer the latest data from the live server to the local environment

Preconditions

  • The local WordPress version is the same as WordPress on the server
  • Expected to use MAMP for the local environment

1. Export the database on phpMyAdmin

First, export the database on phpMyAdmin in order to import it later on the local environment. The steps are as below.

  1. Access phpMyAdmin on the server and select the database
  2. Check ‘Check all / Check tables having overhead
  3. Click the ‘Export’ tab at the top
  4. Configure the following options
    - Export Method: Custom — display all possible options
    - Format: SQL
    - Object creation options: Check the option ‘Add DROP TABLE / VIEW / PROCEDURE / FUNCTION / EVENT / TRIGGER statement’
  5. Click ‘Go’ and exporting is done

2. Copy necessary files from the server

Copy the necessary files from the server to the local environment.

  • /wp-content/themes/the-theme
    This is the theme’s directory.
  • /wp-content/plugins/**
    All plugins are inside of this directory.
  • /wp-content/uploads/**
    All images are inside of this directory.

3. Import the database to local WordPress

Import the database that is downloaded on the machine.

  1. Access phpMyAdmin on the local and select the database
  2. Select the local database for the theme
  3. Click the ‘Import’ tab at the top
  4. Choose the database file exported from the server and click ‘Go
  5. Import has been successfully finished, 185 queries executed. (exported_database.sql)’ will appear if it’s successful

4. Use ‘Database Search and Replace Script in PHP’ to rewrite the URL

1. Download ‘Database Search and Replace Script in PHP

Download Search Replace DB

2. Unzip it and put it in the root directory of the theme on the local

3. Access /Search-Replace-DB-master/ directory
Example:
http://localhost/project-directory/Search-Replace-DB-master/

4. Put the server directory in the text box after ‘replace’ and put the local directory in the text box after ‘with
Example:
replace https:domain.com with http://localhost/project-directory/

Put the server directory and the local directory

5. Click the ‘live run’ button to check and replace everything
Note: Use ‘dry run’ if you need to check what will be replaced

6. After ‘live run’, make sure to click ‘delete me

5. Check on the browser

Go visit the WordPress website on the local server. If everything looks perfect, the migration is successful!

Note: There might be a bug that the lower pages are not loaded properly. In case there is the bug, follow the steps below.

  1. Go to ‘Settings -> Permalinks
  2. Click ‘Save Changes’ without doing anything
  3. Check the lower pages on the browser again

That’s everything I do in order to transfer WordPress from the live server to the local environment.

--

--

Kenta Kodashima

I'm a Software Engineer based in Vancouver. Personal Interests: Books, Philosophy, Piano, Movies, Music, Studio Ghibli.