How do I migrate a wordpress site hosted by digitalocean to another web host? It seems incredibly difficult.

February 15, 2018 591 views
WordPress

It seems digital ocean doesn't allow you to download a full local copy of the site, and it isn't clear how to point mysql to another webhost either. Any tips?

3 Answers

DigitalOcean does not block anyone from migrating their websites / applications around - WordPress included.

There are a few ways to do so - this is one.

  • ssh into your droplet
  • cd /PATH/TO/WEBROOT
  • issue the following command(s):
DBNAME=$(grep DB_NAME "wp-config.php" | cut -d "'" -f 4); \
DBUSER=$(grep DB_USER "wp-config.php" | cut -d "'" -f 4); \
DBPASS=$(grep DB_PASSWORD "wp-config.php" | cut -d "'" -f 4); \
mysqldump -u${DBUSER} -p${DBPASS} ${DBNAME} > ${DBNAME}.sql

This will drop a copy of your database into the same directory as your wordpress installation. Please note this works only for a standard WordPress installation - This can also be done quite easily with phpMyAdmin if it is available.

  • package up everything using whatever archive tool you choose - I prefer zip - zip -r ../html.zip /PATH/TO/WEBROOT

This will place a *.zip archive one directory up.

  • move the archive to the new server scp ../html.zip USERNAME@IP_OR_HOSTNAME:/PATH/TO/WEBROOT

  • Leave your droplet

  • Within the new host create your new database using whichever tool is available or proffered

  • ssh into your new host and cd /PATH/TO/WEBROOT

  • unzip html.zip -d ./

  • copy the old wp-config cp wp-config.php wp-tempfile - we are only going to use this temporarily

  • edit the wp-config.php file updating the database connection details with that of your new host

  • upload the database

OLDDBNAME=$(grep DB_NAME "wp-tempfile" | cut -d "'" -f 4); \
DBNAME=$(grep DB_NAME "wp-config.php" | cut -d "'" -f 4); \
DBUSER=$(grep DB_USER "wp-config.php" | cut -d "'" -f 4); \
DBPASS=$(grep DB_PASSWORD "wp-config.php" | cut -d "'" -f 4); \
mysql -u${DBUSER} -p${DBPASS} ${DBNAME} < ${OLDDBNAME}.sql
  • remove zip archive and wp-tempfile rm -v wp-tempfile html.zip

Please note that this may need to be adjusted to suite your server setup for the source and destination server and wordpress installation - i.e. you may need to install and configure NGINX/APACHE, MySQL/MariaDB etc...

Another solution is to use something like this

https://en-ca.wordpress.org/plugins/wp-migrate-db/

  • Thank you so much for this response. When I type in the first four commands, I get the message in putty "grep: wp-config.php: No such file or directory."

    What do I do from here?

    • Those commands will need to be executed in the root directory of your wordpress installation. Keep in mind I am assuming you are using a standard WordPress installation and not a modified one like roots/bedrock (https://roots.io/bedrock/)

      • Can you give me any further advice? I'm pretty new to this putty stuff and I'm not sure how to resolve the no such file or directory issue.

        • wp-config.php is just the file that holds your database credentials. This file is in the same folder as your WordPress installation

You could use https://transfer.website . I use it usually to migrate Wordpress sites to/from DO for my clients.

Have another answer? Share your knowledge.