In previous articles we discussed about WP CLI. We used to avoid involving WP CLI as most of the new users with cloud, dedicated server may get confused on SSH. Many avoid WP CLI for multi-step CLI works. A Debian installer makes the installation, setup work just easy. This article will guide how to install WP CLI with apt get on Ubuntu server. This guide is usable on server with already running WordPress site as well as fresh server. Fresh blank servers need to install Apache2, PHP 7.2 (latest commonly used at this moment), Percona MySQL. WP CLI will :
- Make WordPress works possible to perform with commands and bash scripts. Hence it is possible to automate more.
- Make WordPress installation easy, avoiding wget, un-tar, moving files steps.
How To Install WP CLI With apt get
You will get official deb, rpm installer here on GitHub :
1 | https://github.com/wp-cli/builds/tree/gh-pages/deb |
You’ll get the apt version on Launchpad :
---
1 | https://launchpad.net/~tiagohillebrandt/+archive/ubuntu/wp-cli |
In order to install WP CLI, we will run :
1 2 3 4 5 | sudo add-apt-repository ppa:tiagohillebrandt/wp-cli ## hit enter/return key to accept apt update apt upgrade apt install wp-cli |
If you are root
user, and run :
1 | wp --help |
You’ll get output like this :
1 2 3 4 5 6 7 8 9 | Error: YIKES! 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 <command> |
You can run commands with :
1 | wp --help --allow-root |
If your current WordPress installation is at /var/www/html
location, then change directory there :
1 | cd /var/www/html |
… then run test commands. If you have another WordPress site at /var/www/wordpress1
location, then you can individually manage it.
We can search WordPress plugin with keyword like SEO
:
1 | wp plugin search seo |
Ideally, you should have an username with root privilage to install (or later manage) WordPress, keep the ownership of WordPress files to username:www-data
. Commonly we use root:www-data
for installation from SSH. You should take care that new plugins, themes are not getting installed with only root
ownership – it can make PHP and WordPress unable to work properly. There is way to manage that, notice the commands :
1 2 3 4 5 6 7 | # update wordpress sudo -u www-data wp core update sudo -u www-data wp core update-db # install plugin sudo -u www-data wp plugin install wordpress-seo sudo -u www-data wp plugin activate wordpress-seo |
To install WordPress in /var/www/html
current dir with database host localhost
, with database name wordpress_db
, database prefix wp_
, database user abhishek
, database password mypassword
, Site
Name The Customize Windows
, URL https://thecustomizewindows.com
, WordPress account username thecustomizewindows
, password loginpassword
, email address admin@thecustomizewindows.com
, command will be :
1 | wp core download --path=/var/www/html && wp core config --dbhost=localhost --dbname=wordpress_db --dbprefix=wp_ --dbuser=abhishek --dbpass="mypassword" && wp db create && wp core install --url=https://thecustomizewindows.com --title="The Customize Windows" --admin_user=thecustomizewindows --admin_password="loginpassword" --admin_email=admin@thecustomizewindows.com |
Conclusion
You can configure WP CLI more – perform database queries, manage user capabilities, manage cron events, import or export content to many works. There are huge resources for information on that topic :
1 2 3 4 5 6 | # resources on wordpress https://make.wordpress.org/cli/handbook/tools/ https://developer.wordpress.org/cli/commands/ # resources on wp-cli http://wp-cli.org/ |