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
- 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
- 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 --opt [DB_NAME] > wp-database.sql
(e.g.,/Applications/MAMP/Library/bin/mysqldump
) (see localwp-config.php
file forDB_USER
,DB_NAME
, andDB_PASSWORD
)
enterDB_PASSWORD
tar -czvf wp-database-`date +%F`.sql.tar.gz wp-database.sql -C my-wp-backups
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 wp-content-`date +%F`.tar.gz wp-content -C my-wp-backups
- 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 wp-database-`date +%F`.sql.tar.gz wp-database.sql -C my-wp-backups
rm wp-database.sql
Second: Upload wp-content
- 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
- 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 - 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
- (Switch production
wp-content
folder:)
mv wp-content wp-content-old && mv wp-content-new wp-content
- (Revert production
wp-content
folder:)
mv wp-content wp-content-new && mv wp-content-old wp-content
Third: Prepare wp-config.php
- 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
- Edit production
wp-config-new.php
file:
nano wp-config-new.php
UpdateDB_NAME
,DB_USER
, andDB_PASSWORD
(and verify$table_prefix
)
control + O (to save), control + X (to exit) - (Switch production
wp-config.php
file:)
mv wp-config.php wp-config-old.php && mv wp-config-new.php wp-config.php
- (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
- 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 localwp-config.php
file forDB_USER
,DB_NAME
, andDB_PASSWORD
) - Gzip local
.sql
file:
tar -czvf wp-database-new.sql.tar.gz wp-database-new.sql
- 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 - (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
- 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
- Switch production
wp-content
folder:
mv wp-content wp-content-old && mv wp-content-new wp-content
- 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
) - Create new production database:
wp db drop ; wp db create
- Import production
.sql
file into production database:
wp db import wp-database-new.sql
- 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]
) - (Revert production wp-content folder:)
mv wp-content wp-content-new && mv wp-content-old wp-content
- (Revert production wp-config.php file:)
mv wp-config.php wp-config-new.php && mv wp-config-old.php wp-config.php
- (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)