- What is the WordPress command line?
WP-CLI is similar to SSH in that it’s a command line. WP-CLI, on the other hand, is only available for WordPress. It is a simple tool, but it’s powerful. This tool allows users to use WordPress the same way as they would with the front end. The flexibility of the WP-CLI is why many WordPress developers use it.
WPCLI is used to:
- Transferring WordPress websites (our case);
- Installing plugins;
- Manage entire multisite networks
- Accessing databases;
- Upgrade core files
Although all the above can still be performed via the web interface, it is preferred to avoid distractions.
- Installing WP CLI
Open your SSH (FastComet uses a custom SSH Port – 17177), and enter the following command.
wp –info
The following error will appear if you don’t have WP-CLI installed:
-bash wp command not found
Installing the WPCLI will fix this problem. Use the following command to access the SSH terminal on your old server. Go all the way back to the root directory to cd to the opt folder. You can get there by running ‘cd/’ repeatedly.
Install using the command:
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
The WP-CLI should be installed. The wp-info order will confirm the installation.
Change the permissions of the file to executable.
chmod +x wp-cli.phar sudo mv wp-cli.phar /usr/local/bin/wp
You can now run the command below to find out the WordPress version:
Wp core –allow-root
It’s all good! We can now take a backup of our WordPress website using WPCLI.
- Backup WordPress files using WP-CLI
The process of creating a backup with WP-CLI and SSH is very similar:
- Create a zip of your WordPress website by running the following command.
zip -r wordpress.zip WordPress
- You can then move the zip folder into your WordPress site directory. Use the command:
mv wordpress.zip
- Remember that WordPress is just a placeholder for your WordPress website’s name.
- You will now find the wordpress.zip file by using the cd command.
- Take a Database Backup
It is easy to back up the database:
- Run this command to create a.sql database file for WordPress:
MySQL -u ewscfaavrd -p ewscfaavrd < site.bak.sql
The Terminal is used to export the backup files to the FastComet Server.
The command line to export the database is:
wp db export
- Import WordPress files to FastComet
- FastComet allows you to launch your Terminal from within cPanel.
- Enter the following command in the public_html directory of the new WordPress website:
wget http://[serverIP]/wordpress.zip
This command will retrieve the zipped file from your old server using a URL.
Note:
It is possible that the get command does not work. You can upload the file using the cPanel’s File Manager if that happens.
- Unzip the contents of the folder once the transfer is complete using the following command.
unzip wordpress.zip
- The following command will move the entire content back into the public_html directory:
mv*../
You’re done! I have successfully moved the WordPress website to the new host.
- When moving a site to another domain, search and replace URLs
This topic has been covered before, so you can skip this step if you’re not moving your WordPress website to a new domain.
You can easily replace URLs pointing to your old domain if you’re migrating.
Run the following command in the Terminal:
wp search-replace “http://old-url.com” “https://new-url.com”
You can use a new domain name by replacing the old one with ‘new-url.
This command will replace all URLs that have your old domain name with the new URL you specify.
Leave a Reply