Adam Cap

  • About
  • Mail
  • Archive/Search

Move from Live Production Environment to Local macOS Development Sandbox (MAMP)

↗︎ Sep 29, 2019⇠ | skip ⇢

This is the converse of slash companion to this guide.

Finalize everything in your live production environment (by adding, removing, editing, and updating plugins, themes, WordPress, content, etc.) before proceeding.

First: Back up

  1. Local wp-content folder:
    open new Terminal window/tab
    cd [Local WordPress Path] (drag WordPress folder from Finder to Terminal to get path)
    mkdir -p my-wp-backups && tar -czvf my-wp-backups/wp-content-`date +%F`.tar.gz wp-content
  2. Local wp-config.php file:
    cp wp-config.php my-wp-backups/wp-config-`date +%F`.php
  3. Local MySQL database:
    [Local mysqldump Path] -u [DB_USER] -p[DB_PASSWORD] --opt [DB_NAME] > wp-database.sql (e.g., /Applications/MAMP/Library/bin/mysqldump) (see local wp-config.php file for DB_USER, DB_NAME, and DB_PASSWORD)
    tar -czvf my-wp-backups/wp-database-`date +%F`.sql.tar.gz wp-database.sql
    rm wp-database.sql
  4. Production wp-content folder:
    open new Terminal window/tab
    ssh username@example.com (e.g., ssh adamcap.com@adamcap.com)
    enter password
    cd [Production WordPress Path] (e.g., cd html)
    mkdir -p my-wp-backups && tar -czvf my-wp-backups/wp-content-`date +%F`.tar.gz wp-content
  5. Production wp-config.php file:
    cp wp-config.php my-wp-backups/wp-config-`date +%F`.php
  6. Production MySQL database:
    wp db export wp-database.sql
    tar -czvf my-wp-backups/wp-database-`date +%F`.sql.tar.gz wp-database.sql
    rm wp-database.sql
  7. Production my-wp-backups folder:
    tar -czvf my-wp-backups.tar.gz my-wp-backups
    (rm my-wp-backups)
    (rm my-wp-backups.tar.gz)

Second: Download my-wp-backups

  1. Download production my-wp-backups folder:
    scp [username@example.com]:[Production WordPress Path]/my-wp-backups.tar.gz [Local Desktop Path] (obtain from web host; e.g., adamcap.com@adamcap.com:/var/www/html/ad/adamcap.com) (drag Desktop from Finder to Terminal to get path or ~/Desktop)

Third: Unzip, rename, and move

  1. Unzip:
    double-click my-wp-backups.sql.tar.gz file on Desktop to unzip folder
    enter folder
    double-click wp-database-`date +%F`.sql.tar.gz file to unzip database
  2. Rename:
    add suffix -new to each item’s file/folder name
  3. Move:
    drag wp-content-new and wp-database-new.sql to local WordPress folder

Fourth: Prepare wp-config.php

  1. Copy local wp-config.php file:
    open new Terminal window/tab
    cd [Local WordPress Path] (drag WordPress folder from Finder to Terminal to get path)
    cp wp-config.php wp-config-new.php
  2. Edit local wp-config-new.php file:
    nano wp-config-new.php
    Update DB_NAME, DB_USER, and DB_PASSWORD (and verify $table_prefix) (be certain to update DB_NAME, e.g., database-XXXX-XX-XX)
    control + O (to save), control + X (to exit)
  3. (Switch local wp-config.php file:)
    mv wp-config.php wp-config-old.php && mv wp-config-new.php wp-config.php
  4. (Revert local wp-config.php file:)
    mv wp-config.php wp-config-new.php && mv wp-config-old.php wp-config.php

Fifth: Import database

  1. Create new local database:
    open new Terminal window/tab
    cd [Local WordPress Path] (drag WordPress folder from Finder to Terminal to get path)
    wp db drop ; wp db create OR drop/create via phpMyAdmin
  2. Switch local wp-content folder:
    mv wp-content wp-content-old && mv wp-content-new wp-content
  3. Switch local wp-config.php file:
    mv wp-config.php wp-config-old.php && mv wp-config-new.php wp-config.php
  4. Import wp-database-new.sql file into local database:
    wp db import wp-database-new.sql OR [Local mysql Path] -u [DB_USER] -p[DB_PASSWORD] [DB_NAME] < wp-database-new.sql (e.g., /Applications/MAMP/Library/bin/mysql)
  5. Search/replace local database:
    wp search-replace $(wp option get siteurl) [Local Site URL](e.g., http://localhost:8888/adamcap or http://adamcap.local)
    (wp search-replace [Production Hostname] [Local Hostname]) (e.g., adamcap.com) (e.g., localhost:8888/adamcap)
    (wp search-replace https://[Production Hostname] http://[Local Hostname]) (e.g, https://adamcap.com) (e.g., http://localhost:8888/adamcap)
  6. Flush rewrite rules (i.e., save permalinks)
  7. (Revert local wp-content folder:)
    mv wp-content wp-content-new && mv wp-content-old wp-content
  8. (Revert local wp-config.php file:)
    mv wp-config.php wp-config-new.php && mv wp-config-old.php wp-config.php
  9. (Delete unneeded/old local files and folders:)
    rm wp-content-new.tar.gz
    rm wp-database-new.sql
    rm wp-database-new.sql.tar.gz
    rm -rf wp-content-old
    rm wp-config-old.php

Me

circa 2010 (22 y/o)

about adam

Recently…

  • 19 May 4: Prevent iOS + WordPress from Replacing Arrows (and Other HTML Symbols) with Emoji #CSS #HTML
  • 19 Mar 23: Move from Live Production Environment to Local macOS Development Sandbox (MAMP) #command line #WordPress
  • 19 Jan 30: Save Jetpack “Site Stats” Pageviews as Post Meta #JavaScript #PHP #WordPress
  • 19 Jan 26: Use Git to Manage WordPress Projects Developed Locally on macOS #command line #WordPress
  • 19 Jan 18: Fix Line Height for Input Placeholders in Safari #CSS
  • 19 Jan 18: Add Partner/Associates/Tracking ID/Tag to Amazon Links #PHP #regex #WordPress
  • 19 Jan 18: Add Fancybox Attribute to Image Links #PHP #regex #WordPress
  • 19 Jan 18: Automatically Bold (or Style) the First X Words of Content #PHP #regex #WordPress
  • 19 Jan 16: Move from Local macOS Development Sandbox (MAMP) to Live Production Environment #command line #WordPress
  • 19 Jan 15: Add Media/Attachment Source Fields (and Display Image Sources in Content) #PHP #regex #WordPress
  • 19 Jan 7: Remove Nonbreaking Spaces (&nbsp;’s) from Content and Text Widgets #PHP #WordPress
archive

More…
command line (Language) / WordPress (Tag) / code (Post Type)

⇠ Previous
Next code ⇢
  • Home
  • About
  • Archive
  • Mail
  • Random
  • Dingus
  • Reading
  • Code

ADAM CAP is an elastic waistband enthusiast, hammock admirer, and rare dingus collector hailing from Berwyn, Pennsylvania.

My main interests at this time include reading, walking, and learning how to do everything faster.

Psst: If you find my website helpful or enjoyable, please join my newsletter and/or send me an email—I want to hear from you!

Disclosure: As an Amazon Associate I earn from qualifying purchases.

© 2009–2023 Adam Cap(riola) top ⇡