Adam Cap

  • About
  • Mail
  • Archive/Search

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

↗︎ Mar 24, 2019⇠ | skip ⇢

Follow these steps to move a local, MAMP development environment to a live, production environment (that has shell and WP-CLI enabled; good web hosts do). We will be using command line to achieve this end. The reason to use command line instead of graphical interfaces, like the myriad of available (S)FTP clients or phpMyAdmin, is that command line lends better performance and reliability. Graphical interfaces will time out, or seemingly take forever to load, if your files are large. There is a higher learning curve to command line—it will feel initially like yawping haphazardly into a void—but the reaped time savings make it well worth practicing.

Finalize everything in your local development environment (by adding, removing, editing, and updating plugins, themes, WordPress, content) 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 wp-content-`date +%F`.tar.gz wp-content -C my-wp-backups
  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 --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)
    enter DB_PASSWORD
    tar -czvf wp-database-`date +%F`.sql.tar.gz wp-database.sql -C my-wp-backups
    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 wp-content-`date +%F`.tar.gz wp-content -C my-wp-backups
  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 wp-database-`date +%F`.sql.tar.gz wp-database.sql -C my-wp-backups
    rm wp-database.sql

Second: Upload wp-content

  1. Gzip local wp-content folder:
    open new Terminal window/tab
    cd [Local WordPress Path] (drag WordPress folder from Finder to Terminal to get path)
    mv wp-content wp-content-new && tar -czvf wp-content-new.tar.gz wp-content-new && mv wp-content-new wp-content
  2. Upload local .tar.gz file to production:
    open new Terminal window/tab
    scp [Local .tar.gz Path] [username@example.com]:[Production WordPress Path] (drag .tar.gz file from Finder to Terminal to get path) (obtain from web host; e.g., adamcap.com@adamcap.com:/var/www/html/ad/adamcap.com)
    enter password
  3. Unzip production .tar.gz file:
    ssh username@example.com (e.g., ssh adamcap.com@adamcap.com)
    enter password
    cd [Production WordPress Path] (e.g., cd html)
    mkdir wp-content-new && tar -xzvf wp-content-new.tar.gz -C wp-content-new --strip-components 1
  4. (Switch production wp-content folder:)
    mv wp-content wp-content-old && mv wp-content-new wp-content
  5. (Revert production wp-content folder:)
    mv wp-content wp-content-new && mv wp-content-old wp-content

Third: Prepare wp-config.php

  1. Copy production wp-config.php file:
    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)
    cp wp-config.php wp-config-new.php
  2. Edit production wp-config-new.php file:
    nano wp-config-new.php
    Update DB_NAME, DB_USER, and DB_PASSWORD (and verify $table_prefix)
    control + O (to save), control + X (to exit)
  3. (Switch production wp-config.php file:)
    mv wp-config.php wp-config-old.php && mv wp-config-new.php wp-config.php
  4. (Revert production wp-config.php file:)
    mv wp-config.php wp-config-new.php && mv wp-config-old.php wp-config.php

Fourth: Move database

  1. Export local MySQL database:
    open new Terminal window/tab
    cd [Local WordPress Path] (drag WordPress folder from Finder to Terminal to get path)
    [Local mysqldump Path] -u [DB_USER] -p[DB_PASSWORD] --opt [DB_NAME] > wp-database-new.sql (e.g., /Applications/MAMP/Library/bin/mysqldump) (see local wp-config.php file for DB_USER, DB_NAME, and DB_PASSWORD)
  2. Gzip local .sql file:
    tar -czvf wp-database-new.sql.tar.gz wp-database-new.sql
  3. Upload local .tar.gz file:
    open new Terminal window/tab
    scp [Local .tar.gz Path] [username@example.com]:[Production WordPress Path] (drag .tar.gz file from Finder to Terminal to get path) (obtain from web host; e.g., adamcap.com@adamcap.com:/var/www/html/ad/adamcap.com)
    enter password
  4. (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
  5. Unzip production .tar.gz file:
    ssh [username@example.com] (e.g., ssh adamcap.com@adamcap.com)
    enter password
    cd [Production WordPress Path] (e.g., cd html)
    tar -xzvf wp-database-new.sql.tar.gz
  6. Switch production wp-content folder:
    mv wp-content wp-content-old && mv wp-content-new wp-content
  7. Switch production wp-config.php file:
    mv wp-config.php wp-config-old.php && mv wp-config-new.php wp-config.php
    (wp config shuffle-salts)
  8. Create new production database:
    wp db drop ; wp db create
  9. Import production .sql file into production database:
    wp db import wp-database-new.sql
  10. Search/replace production database:
    wp search-replace $(wp option get siteurl) [Production Site URL] (e.g., wp search-replace $(wp option get siteurl) https://adamcap.com)
    (wp search-replace [Local Hostname] [Production Hostname])
    (wp search-replace http://[Production Hostname] https://[Production Hostname])
  11. (Revert production wp-content folder:)
    mv wp-content wp-content-new && mv wp-content-old wp-content
  12. (Revert production wp-config.php file:)
    mv wp-config.php wp-config-new.php && mv wp-config-old.php wp-config.php
  13. (Delete unneeded/old production 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

See Also

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

Me

circa 2009 (21 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 ( ’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 ⇡