There is so many ways to moving or cloning aWordpress
website. You can use a wordpress plugin. You can move your wordpress files and your data, then you can update your database on the new server. Nowadays, the hosting control panels (like cPanel and Plesk) are supporting move and clone operations with own tools like WP Toolkit
.
Usually, every wordpress admin moving or cloning their websites in classic way. In the classic way, you’re archiving your website files and exporting database, then you’re moving them into new server, extracting files new location and import database, then changing your credentials. But, if you’re moving it to another website or cloning, you have extra duty about the changing links on the database. Its hard to find and replace on the tables and their thousands rows.
In my way, you don’t need to use phpmyadmin for replacing old links with new ones. But, we need SSH Access and wp-cli for it. I will assume you have it.
Prerequisities
- SSH Access
- wp-cli
Installation of WP CLI
Firstly, you need to download WP CLI into your server.
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
Then, you should give +x
chmod permission to phar file and then, you can move it under /usr/local/bin
directory.
chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/php
You can test the binary file with following command.
wp --info
Moving Files and Databases
Go to the directory where you files are located. Then, create an archive for your files and compress it.
tar -czvf bckp-wp.tar.gz * .htaccess
Find your database credentials.
cat wp-config.php | grep DB
Then, use mysqldump
command for export it.
mysqldump -u MYSQLUSER -p MYSQLDATABASE > MYSQLDATABASE.sql
Enter your database password and wait it until complete.
Now, you are ready to moving. You can download archive and sql files on your computer or you can download them with wget
in your new server. I assumed you have new server, but if you will use same server, you can copy or move your files to new location.
Extract your files in new location.
tar -zxvf bckp-wp.tar.gz
Give owner and group rights to the files.
chown -R user:user * .htaccess
Import your database to new database.
mysql -u MYSQLUSER -p MYSQLDATABASE < MYSQLDATABASE.sql
Changing Old Links with New Ones
Now, you have the same files and the same database in your new location. Just we need to replace whole links with new ones. We have just single command for it.
wp search-replace "https://aaa.com" "https://bbb.com" --allow-root
And, you can replace also http links to https with new domain name.
wp search-replace "http://aaa.com" "https://bbb.com" --allow-root
Cleanup
You should delete the archive and sql file from both of servers. Because, there is too many harmful bots on the internet for find archive and sql files located publicly.
Conclusion
That’s it 👋 You’re ready to share your website link with followers.
I didn’t write every single steps into the article like “create database, give permissions to users etc.” Because, if you don’t know this steps already or if you can’t use linux properly, this article is not fit with you.