To check, if your server has WP-CLI already installed or not, running the following command :

wp

 

If you see the error below wp-cli is not installed, you can continue with the tutorial to install it on the server.

[root@host ~]# wp –info
-bash: wp: command not found

 

If you see actual command output,  with the arguments listed then it means WP-CLI is already installed.

 

Installation Steps

 

1. We will first download wp-cli.phar file by the following command

curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar

 

2. Give executable permission to the file downloaded

chmod +x wp-cli.phar

 

3. Finally, we will move the wp-cli.phar executable to a global location to ensure all users have access.

sudo mv wp-cli.phar /usr/local/bin/wp

 

We have successfully installed WP-CLI. To verify the same, run the following command

wp

 

Error:  It looks like you’re running this as root. You probably meant to run this as the user that your WordPress install exists under. If you REALLY mean to run this as root, we won’t stop you, but just bear in mind that any code on this site will then have full control of your server, making it quite DANGEROUS.

 

If you’d like to continue as root, please run this again, adding this flag: –allow-root

 

If you’d like to run it as the user that this site is under, you can run the following to become the respective user:

sudo -u USER -i — wp

 

To create WordPress Instance with WP-CLI in Wordpress

 

Prerequisites:

Root level SSH access to server.

WP-CLI installed.

 

Steps:

1. After making the ssh connection to your server, navigate to the directory where you want to install the wordpress website

 

2. Running the following command will install the wordpress instance. Do replace the arguments/parameters used in the command like URL, Title, Admin Username, Password, and Admin Email.

wp core install —url=your_domain —title=Your_Blog_Title —admin_user=username —admin_password=password —admin_email=your_email.com

 

Backup database using WP-CLI in Wordpress

 

Prerequisites:

Root level SSH access to server

WP-CLI installed.

 

 Steps:

1. After connecting to the server, move to the directory where your wp-config file resides

cd /home/rootadminz/public_html

 

2. Run the following command to take backup :

wp export

 

Import database using WP-CLI in wordpress

 

Prerequisites:

Root level SSH access to a server

WP-CLI installed.

 

Steps:

1. After connecting to the server, move to the directory where your wp-config file resides

 

cd /home/rootadminz/public_html

 

2. Run the following command to import the database :

 

wp db import rootadminz_database.sql

 

This will successfully import the backed up db sql file into the WordPress database.

 

Esta resposta lhe foi útil? 0 Usuários acharam útil (1 Votos)