How to Set Up WordPress Using WP Client

WP CLI: Command LIne Interface for WordPress

Time is valuable, and here at Balystic we take that very seriously.  Because we set up a good amount of instances in really short periods of time, we are always looking for ways where we can have our WordPress instances up and running as quickly as possible.

For this, we are now using WP CLI tool.  WP CLI , as its name says, is a Command Line Interface for WordPress (what Drush is to Drupal), and it allows to manage almost all of your instances from the Terminal.

The process to install WP CLI is very simple (as you can see in the official documentation of WP CLI,) whether you want to have it system-wide or just have it set up for those particular instances you want to use it for. Make sure you have it set it up correctly before performing any of the commands to follow.

Now, I’m going to explain each of the commands we use to have a WordPress instance in just a few seconds.

Download the WordPress core files using the terminal

At this stage, we are assuming the database has already been created. We can start downloading the WordPress core files, this is the command:

$ wp core download
  • wp: This is the way to invoke WP-CLI from the Terminal if you have it installed globally for your system.
  • core: This subcommand is in charge of executing all task related to WordPress core (like download the core files, update it, create the wp-config.php file, etc)
  • download: this subcommand specifies the task wanted to be executed by the core; all WordPress files from latest version will be downloaded to the directory from where the command is executed.

Set up the WordPress instance

The WordPress files are now in place, and what is pending is setting up the instance (or set up the wp-config.php file with the database connection parameters.)  This can be accomplished with the following command:

$ wp core config --dbhost=<DB_HOST> --dbuser=<DB_USER> --dbpass=<DB_USER_PASS> --dbname=<DB_NAME>

The first two elements of this command are familiar (check them in the details of the first command), but let’s review the new ones:

  • config: this subcommand generates the wp-config.php file, using the option values passed.
  • –dbhost=<DB_HOST>:  this is the host where the MySQL server is running (it uses localhost as the default value)
  • –dbuser=<DB_USER>: the MySQL user to connect to the server (note: it should be a user with limited permissions.)
  • –dbpass=<DB_USER_PASS>: the password for MySQL user (a strong one, please!)
  • –dbname=<DB_NAME>: the name of the database (which should be created already.)

Install the WordPress database

With the files in place and the wp-config file set, the last pending part is installing the WordPress database. The command for this last step is:

$ wp core install --url=<SITE_URL> --title=<SITE_TITLE> --admin_user=<ADMIN_USERNAME> --admin_password=<ADMIN_PASSWORD> --admin_email=<ADMIN_EMAIL> --skip-email
  • install: this subcommand installs the WordPress database using the parameters set in the wp-config.php file.
  • –url=<SITE_URL>: This is the URL where the WordPress can be reached.
  • –title=<SITE_TITLE>: The title for the instance. If the title has white spaces, it should be wrapped between quotes (“).
  • –admin_user=<ADMIN_USERNAME>: The username for the WordPress admin (try not to use admin or something easy to guess.)
  • –admin_password=<ADMIN_USERNAME>: The admin’s password (as for the database user password, again, a strong one!)
  • –admin_email=<ADMIN_USERNAME>: The admin’s email.
  • –skip-email: Admin gets notified once the instance is ready. This flag will prevent this notification from being sent.

Pro tip: combine the commands to set up WordPress in seconds

Now that it is understood what each of these commands do, they can be combined in a single Bash instruction to have the instance up and running in just a couple seconds (actually in less than one second, if it is run from a machine with good performance and a strong internet connection):

$ wp core download \

&& wp core config --dbhost=<DB_HOST> --dbuser=<DB_USER> --dbpass=<DB_USER_PASS> --dbname=<DB_NAME> \

&& wp core install --url=<SITE_URL> --title=<SITE_TITLE> --admin_user=<ADMIN_USERNAME> --admin_password=<ADMIN_PASSWORD> --admin_email=<ADMIN_EMAIL> --skip-email

It is now completely set up and just waiting for you to start using it!

Know of a faster way to have a WordPress instance up and running? Have any questions about these steps? Let us know in the comments. On the other hand, if you need help setting up your WordPress instance, give us a call or shoot us a quick message for an instant consultation.

 

Liked this post? Follow us on Facebook and Twitter for tips and tricks, news, and a peek behind-the-scenes of Balystic.