Move WordPress site via terminal
Development Server
Set your development creds
CUR_URL=development.server.com
CUR_DB_HOST=database_host
CUR_DB_NAME=database_name
CUR_DB_USER=database_user
CUR_DB_PASS=database_password
CUR_PATH=/path/to/site/
New Server Info
NEW_URL=production.server.com
NEW_DB_HOST=new_database_host
NEW_DB_NAME=new_database_name
NEW_DB_USER=new_database_user
NEW_DB_PASS=new_database_password
Backup zip location and name
BACKUPMYSQLFILE=mysqlbackup.sql
BACKUPFILE=siteexport.tgz
export Database
mysqldump -h localhost -u $CUR_DB_USER -p$CUR_DB_PASS $CUR_DB_NAME > $CUR_PATH$BACKUPMYSQLFILE
find and replace old URLs in SQL file
sed -i “s/${CUR_URL}/${NEW_URL}/g” $CUR_PATH$BACKUPMYSQLFILE
find and replace old Database Info in wp-config.php file
sed -i.backup -e”s/define(‘DB_NAME’, ‘${CUR_DB_NAME}’);/define(‘DB_NAME’, ‘${NEW_DB_NAME}’);/g” -e”s/define(‘DB_USER’, ‘${CUR_DB_USER}’);/define(‘DB_USER’, ‘${NEW_DB_USER}’);/g” -e”s/define(‘DB_PASSWORD’, ‘${CUR_DB_PASS}’);/define(‘DB_PASSWORD’, ‘${NEW_DB_PASS}’);/g” -e”s/define(‘DB_HOST’, ‘${CUR_DB_HOST}’);/define(‘DB_HOST’, ‘${NEW_DB_HOST}’);/g” ${CUR_PATH}wp-config.php
change to the directory of the site, zip it up and move it into the document root
cd ${CUR_PATH} && tar -czf ../${BACKUPFILE} .
mv ../$BACKUPFILE $CUR_PATH
Production Server
Setup production creds
OLD_URL=http://someURL.com/
NEW_PATH=/path/to/site/
NEW_DB_HOST=some_host
NEW_DB_NAME=database_name
NEW_DB_USER=database_user_name
NEW_DB_PASS=database_password
download and extract site backup zip file
wget {$OLD_URL}siteexport.tgz
tar -xsf siteexport.tgz -C {$NEW_PATH}
import data into database
mysql -h {$NEW_DB_HOST} -D {$NEW_DB_NAME} -u {$NEW_DB_USER} -p’{$NEW_DB_PASS}’ < {$NEW_PATH}mysqlbackup.sql
clean up files
rm {$NEW_PATH}siteexport.tgz
rm {$NEW_PATH}mysqlbackup.sql
see full bashscripts here, https://gist.github.com/wookiecooking/5578175
Written by Austin Turnage
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Mysql
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#