Over the years I’ve migrated a lot of WordPress sites. Although there are plugins that can take care of it, I have yet to find a more efficient way than just doing it by hand. The following is my recipe for migrating WordPress instances.
In the example we move a site to our local development environment.
The quickest way is to use wp-cli:
cd public_html
wp db dump example.com.sql
If that doesn’t work, here’s the manual way:
cd public_html
# Find database credentials
grep DB_ wp-config.php
# Create a database dump
mysqldump somedb -u someuser -p'somepassword' > example.com.sql
Make a tarball of the site’s files:
tar czf example.com.tgz public_html
If it’s only for testing and you’re in a hurry, exclude the WP Uploads directory:
tar czf example.com.tgz --exclude=**/wp-content/uploads/* public_html
Now copy the tarball over to your machine.
tar xzf example.com.tgz
sudo mysqladmin create example_com
cd public_html
wp db cli < example.com.sql
FORCE_SSL_ADMIN
” from wp-config.phpwp search-replace https://example.com http://localhost:8080
wp server --port=8080
You should now be able to access the WordPress site by visiting http://localhost:8080 !
Create an admin user for yourself:wp user create myadmin [email protected] --role=administrator --user_pass=admin
If connecting to the database fails, it could be that an empty password is not accepted. As using root with an empty password is a bit of a hack, here’s another hack to make it work for newer versions of MySQL/MariaDB. Obtain a root MySQL shell and execute:
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '';
FLUSH PRIVILEGES;
See WordPress development tricks