With Cloud Automation, we can integrate WP-CLI, a command line tool for WordPress for better, easy and faster management on Cloud Server. As we have discussed before, there is huge change in Automation in the Cloud in recent time. Software defined, Bare Metal hosting with the flexibilities of a typical cloud IaaS are emerging now. Chef Software is rocking on OpenStack Cloud Software for IaaS and OpenShift PaaS. Providers like Rackspace has blueprints which uses WP-CLI for their Rackspace Deployments product. We talked about WordPress Command Line Tool before, the tool is same but we are elaborating something more.
WP-CLI and Cloud Server
For using WP-CLI on Cloud Server (we are assuming that you are using latest LTS version of Ubuntu on OpenStack Cloud, i.e. Ubuntu 14.04 at the time of publication of this article), you need to have a minimum knowledge on bash profile. You can read articles like Can Not Find .Profile File OS X, Change $PATH Variable on OS X for minimum idea on profiles on UNIX or UNIX Like Operating Systems / Linux. There will be not much difference in commands between OS X and Ubuntu except some Philosophical matters like Wheel Group, file permissions, source code etc. The reason to point to these articles is that; we will create a .bash_profile
file for our root user and add the path to the wp-cli
executable. The source code of WP-CLI is available here :
1 | https://github.com/wp-cli/wp-cli |
We can cURL the bash script from raw github :
---
1 | https://raw.githubusercontent.com/wp-cli/wp-cli.github.com/master/installer.sh |
Also, chef cookbook is available for wp-cli
:
1 | https://github.com/francescolaffi/chef-wp-cli |
In this article WP-CLI and Cloud Server, we will discuss about the traditional WP-CLI, not the chef cookbook wp-cli.
WP-CLI and Cloud Server : Getting Started Guide
This is a bit complicated setup and demands minimum working experience with UNIX systems, if you are a new user; you should follow the plain one server WordPress Setup guide on Ubuntu. We will not need to do the steps like :
1 2 3 4 | ~ cd /var/www/html && rm index.html # download wordpress ~ wget http://wordpress.org/latest.tar.gz [...] |
So, let us get started with WP-CLI installation. First, we will cURL the bash script to install wp-cli :
We should install git first, just a customary update and installing git after you SSH to the server instance as root
:
1 | apt-get update && apt-get install git |
We will install wp-cli with two commands :
1 2 3 4 5 6 | curl https://raw.github.com/wp-cli/wp-cli.github.com/master/installer.sh && installer.sh bash # one can avoid && and use fully two separate commands curl https://raw.github.com/wp-cli/wp-cli.github.com/master/installer.sh installer.sh bash # technically it should work with one command curl https://raw.githubusercontent.com/wp-cli/wp-cli.github.com/master/installer.sh | bash |
As we said, we need to work with bash profile :
1 2 3 4 5 6 7 8 9 10 11 12 | nano ~/.bash_profile # add these lines export PATH=/root/.wp-cli/bin:$PATH source $HOME/.wp-cli/vendor/wp-cli/wp-cli/utils/wp-completion.bash alias wp="wp --allow-root" # do not add these lines. Try # ' instead of " # alias wp='wp --allow-root' # Typography and keyboard mapping can change # what we typed / wanted to show depending on OS # save the file # ^ + O writes, ^ + X exits |
The third line; alias wp="wp --allow-root"
is optional and to avoid specifying " --allow-root"
while using wp
as command by root user. You can read Create Aliases on OS X and Linux for Faster Work on Command Line for explanation. You can read more on alias part :
1 | http://ss64.com/bash/alias.html |
We should load the environment :
1 | source ~/.bash_profile |
You should work here :
1 | cd /home/wordpress/public_html |
You can install wordpress with this command :
1 2 3 4 5 6 7 8 9 10 11 12 13 | wp core install --url="edit_domain_name" --title="Edit Blog Title" --admin_user="edit_admin" --admin_password="put_password" --admin_email="edit_email" # output # Success: WordPress installed successfully. # kind on manual wp help # get list of posts wp post list # output +----+--------------+-------------+---------------------+-------------+ | ID | post_title | post_name | post_date | post_status | +----+--------------+-------------+---------------------+-------------+ | 1 | Hello world! | hello-world | 2014-06-07 21:02:09 | publish | +----+--------------+-------------+---------------------+-------------+ |
Yes, we can run database related commands too :
1 2 3 4 5 6 7 | wp db query "SELECT user_login,ID FROM wp_users;" # output +------------+----+ | user_login | ID | +------------+----+ | admin | 1 | +------------+----+ |
It is not our work to copy paste the example usages :
1 2 | http://wp-cli.org/commands/ https://github.com/wp-cli/wp-cli/wiki/Community-Packages |
That is all about WP-CLI we wanted to tell you. For Rackspace Deployment, the wp-cli
is programmatically deleted. They probably use Checkmate and OpenStack Heat, more complex, easy for the end user :
1 | https://github.com/rackspace-orchestration-templates/wordpress-single |