fbpx

Add WP-CLI to CPanel

WP-CLI has some incredible commands, and you should be able to use them on your CPanel hosted website. The following steps will allow you to add WP-CLI to CPanel with or without Sudo Access.

Step 1: Login to CPanel and Open Terminal

Typically, to login to a CPanel hosted website, you would go to yourwebsite.com:2083 and enter in your CPanel credentials. Then, you want to search for Terminal in the CPanel dashboard or click on the Terminal icon in the Advanced section.

Step 2: Download WP-CLI

Now that terminal has loaded, navigate to /tmp by entering in the following command:

cd /tmp

Then, install WP-CLI by downloading it with wget, using the following command:

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

OR, you could add WP-CLI by using the following curl command:

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

Step 3: Make it Executable

Modify the file so that it is executable, by running the following chmod command:

chmod +x wp-cli.phar

If you have sudo access, run the following command, which would allow you to use WP-CLI commands globally:

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

Step 4: Run your WP-CLI Command

Running the WP-CLI command of your choice is super easy, all you have to do is make sure you are in the /tmp directory and use ./wp-cli.phar in place of wp. You can check that WP-CLI is installed properly by running the following command

./wp-cli.phar --info

So, for example, to run the wp search-replace command, you would use the following command:

./wp-cli.phar search-replace 'http://www.old-website.com/' 'http://www.new-website.com/'

If you have sudo access and moved the wp-cli.phar file to /usr/local/bin/wp, you should be able to call WP-CLI regularly. For example, you would check that everything has been added correctly by running the following command:

wp --info

And, then given our wp search-replace command above, you would use the following command if you followed our sudo instructions:

wp search-replace 'http://www.old-website.com/' 'http://www.new-website.com/'

Leave a Reply

Your email address will not be published. Required fields are marked *