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.
tar czf example.com.tgz public_html
tar czf example.com.tgz --exclude=**/wp-content/uploads/* public_html
grep DB_ public_html/wp-config.php
mysqldump somedb -u someuser -p'somepassword' | gzip > example.com.sql.gz
Now copy the tarball and ‘sql-ball’ over to your machine.
tar xzf example.com.tgz
sudo mysqladmin create example_com
zcat example.com.sql.gz | sudo mysql example_com
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