Categories
Firewall

WP-CLI common commands

WP-CLI is a set of command-line tools for managing WordPress installations. You can update plugins, set up multisite installs and much more, without using a web browser.

Requirement of WP-CLI utility

Requirement
PHP 5.4 or later
WordPress 3.7 or later
  • Download WP-CLI utilty through wget or curl
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
  • Check if it works
php wp-cli.phar --info 
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 ...
php wp-cli.phar --info --allow-root
PHP binary:	
PHP version:	5.3.3
php.ini used:	/etc/php.ini
WP-CLI root dir:	phar://wp-cli.phar
WP-CLI global config:	
WP-CLI project config:	
WP-CLI version:	0.16.0

To be able to type just wp, instead of php wp-cli.phar, you need to make the file executable and move it to somewhere in your PATH. For example

chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp
[[email protected]_1 wordpress]# wp --allow-root --info
PHP binary:	
PHP version:	5.3.3
php.ini used:	/etc/php.ini
WP-CLI root dir:	phar://wp-cli.phar
WP-CLI global config:	
WP-CLI project config:	
WP-CLI version:	0.16.0
[[email protected]_1 wordpress]# wp --allow-root theme status
3 installed themes:
  A twentyfourteen 1.1
  I twentythirteen 1.2
  I twentytwelve   1.4

Legend: A = Active, I = Inactive
  • Installation of plugin hello-dolly through WP-CLI
[[email protected]_1 httpdocs]# wp --allow-root plugin install hello-dolly
Installing Hello Dolly (1.6)
Downloading install package from https://downloads.wordpress.org/plugin/hello-dolly.1.6.zip...
Unpacking the package...
Installing the plugin...
Plugin installed successfully.
  • Check WP core version
[[email protected]_1 httpdocs]# wp --allow-root core version
3.9.2
  • Check plugin status
[[email protected]_1 httpdocs]# wp --allow-root plugin status
3 installed plugins:
  I akismet     3.0.1
  I hello-dolly 1.6
  I hello       1.6

Legend: I = Inactive

NOTE: If you have update version of plugin it will show like this

Legend: I = Inactive, A = Active, U = Update Available
  • Updating WordPress, Updating WordPress is simple with WP-CLI. To do this, type the following command:
wp core update
  • Whenever you update WordPress, you should also update the database. To do this, type the following command
wp core update-db
  • Backing up and restoring a WordPress database

It is a good idea to periodically back up your WordPress database. By combining WP-CLI’s backup functionality with a cron job, you can automatically back up your database on a set schedule.

To back up a WordPress database using WP-CLI, type the following command:

wp db export
Success: Exported to test1.sql

When this command finishes, you have a .sql file that you can store in a safe location. If you need to import a database into WordPress at some point, type the following command. Replace filename with the name of the database backup file:

wp db import test1.sql
Success: Imported from test1.sql
  • Update themes
[[email protected]_1 httpdocs]# wp --allow-root theme update webby-blue-10
  • Delete Themes
[[email protected]_1 httpdocs]$ wp --allow-root theme delete webby-blue-10
Success: Deleted 'webby-blue-10' theme.
  • Update WP plugins
[[email protected]_1 httpdocs]# wp --allow-root plugin update akismet
Success: Successfully executed the cron event 'wp_update_plugins'
  • Delete WP Plugin
[[email protected]_1 httpdocs]# wp --allow-root plugin deactivate akismet && wp --allow-root plugin delete akismet

By Sushant Chawla

Over the past 11 years I have acquired very good knowledge of:

- Cloud Setup on Amazon, Rackspace with autoscaling, load balancers, etc
- LAMP architecture
- LNMP Architecture
- Apache, Nginx, Lighttpd
- Databases: MySQL and PostgreSQL
- Bash Scripting
- Configuration Management with Puppet
- Monitoring: Nagios, Zabbix, ICINGA
- Mail servers: Sendmail, Postfix, Exim
- Web Accelerators & Caching Setups with Memcache, Varnish & Redis
- Setup and Management of high availability applications clusters
- LDAP, Samba, NFS, FTP, DNS, DHCP, Openfire, Squid Proxy
- Subversion(SVN), GIT
- Control Panels: Plesk, Webmin, cPanel

Apart from Linux, I am a great sports star & regular traveller. I like working out and exploring various places.

Cheers ;-)

Leave a Reply

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