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
- 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
- Local
wp-config.php
file:
cp wp-config.php my-wp-backups/wp-config-`date +%F`.php
- 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 localwp-config.php
file forDB_USER
,DB_NAME
, andDB_PASSWORD
)
tar -czvf my-wp-backups/wp-database-`date +%F`.sql.tar.gz wp-database.sql
rm wp-database.sql
- 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
- Production
wp-config.php
file:
cp wp-config.php my-wp-backups/wp-config-`date +%F`.php
- 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
- 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
- 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
- Unzip:
double-clickmy-wp-backups.sql.tar.gz
file on Desktop to unzip folder
enter folder
double-clickwp-database-`date +%F`.sql.tar.gz
file to unzip database - Rename:
add suffix-new
to each item’s file/folder name - Move:
dragwp-content-new
andwp-database-new.sql
to local WordPress folder
Fourth: Prepare wp-config.php
- 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
- Edit local
wp-config-new.php
file:
nano wp-config-new.php
UpdateDB_NAME
,DB_USER
, andDB_PASSWORD
(and verify$table_prefix
) (be certain to updateDB_NAME
, e.g.,database-XXXX-XX-XX
)
control + O (to save), control + X (to exit) - (Switch local
wp-config.php
file:)
mv wp-config.php wp-config-old.php && mv wp-config-new.php wp-config.php
- (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
- 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 - Switch local
wp-content
folder:
mv wp-content wp-content-old && mv wp-content-new wp-content
- Switch local
wp-config.php
file:
mv wp-config.php wp-config-old.php && mv wp-config-new.php wp-config.php
- 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
) - Search/replace local database:
wp search-replace $(wp option get siteurl) [Local Site URL]
(e.g.,http://localhost:8888/adamcap
orhttp://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
) - Flush rewrite rules (i.e., save permalinks)
- (Revert local wp-content folder:)
mv wp-content wp-content-new && mv wp-content-old wp-content
- (Revert local wp-config.php file:)
mv wp-config.php wp-config-new.php && mv wp-config-old.php wp-config.php
- (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