What is WP-CLI and why do I need it?
You don’t need
WP-CLI to run a WordPress site but,
WP-CLI is WordPress deployed from the command line and mainly used for headless admin installs but everything you can do with regular WordPress you can do with
WP-CLI It works great as a REST API interface especially since you don’t need a frontend, which we all know is notoriously sluggish without some fine-tuning.
You can use
WP-CLI to install WordPress without a frontend, then use a much faster static site frontend generator like Gatsby for blazing fast speeds.
Installing WP-CLI on CloudPanel.
WP-CLI on CloudPanel first we need to create a
sudo user. This is different from adding users through the
admin > users section on CloudPanel (this is to add users that can log into the control panel via HTTPS).
First, we will need to log in as
root to add the user and set the permissions.
Log into SSH as root.
Once logged in we can add the user and give them
sudo privileges with the following two commands.
adduser wpcli-user usermod -aG sudo wpcli-user
Now we can log out of root and log back in with the new user.
Once logged in as your newly created non root
sudo user use curl to download
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
You can check it works with.
php wp-cli.phar --info
Mark executable & move to PATH.
Now we need to mark the file executable and move it to somewhere within your path.
chmod +x wp-cli.phar sudo mv wp-cli.phar /usr/local/bin/wp
Let’s check it’s all working as intended.
wp cli info
You should get some information back similar to below.
[email protected]:~$ wp cli info OS: Linux 5.10.0-16-amd64 #1 SMP Debian 5.10.127-2 (2022-07-23) x86_64 Shell: /bin/bash PHP binary: /usr/bin/php8.1 PHP version: 8.1.8 php.ini used: /etc/php/8.1/cli/php.ini MySQL binary: /usr/bin/mysql MySQL version: mysql Ver 8.0.27-18 for Linux on x86_64 (Percona Server (GPL), Release '@@[email protected]@', Revision '@@[email protected]@') SQL modes: WP-CLI root dir: phar://wp-cli.phar/vendor/wp-cli/wp-cli WP-CLI vendor dir: phar://wp-cli.phar/vendor WP_CLI phar path: /home/wpcli-user WP-CLI packages dir: WP-CLI global config: WP-CLI project config: WP-CLI version: 2.6.0
What about other users?
You should now be able to log out with your
sudo user and log back in with any other user that doesn’t have
sudo privileges and still be able to use the
wp cli info command. This shows us that
WP-CLI is working as intended.
Setting up your first project.
The following command will download, install and set up your first admin WordPress user.
wp core install --url=wpcli-test.dazeb.uk --title="Your Blog Title" --admin_name=ADMINLOGIN --admin_password=ADMINPASSWORD [email protected]
Just be sure to change the
You have now enabled and installed WordPress via the