Wordpress made easy with WP CLI

Tom Large
3 min readJun 16, 2018

Let me show you something that will change the way you start your Wordpress sites with WP CLI. Until now I used to download the Wordpress package from wordpress.org and then unzip all files and then move them to where I want them. Then I need to set up the wp-config and so on. It’s a very long process definitely when you do this day in day out.

Wordpress CLI makes this so simple! Let me show you how!

Installing Wordpress CLI

First of all you need to install the CLI. You will also need to have Composer installed on your machine if you haven’t follow this link and run the commands before you continue. Open your terminal and do the following

This downloads the package file to your machine

$ curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar

This will check if it works

$ php wp-cli.phar --info

This allows you 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.

$ chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp

Now try running wp --info. If WP-CLI is installed successfully, you’ll see output like this:

There you go! Wordpress CLI is now installed!

Create you first Wordpress site with CLI

Now you have everything installed you will want to get started. I’m sure you already know this but you will need to have MAMP or something like this that runs your local server.

First of all you need to make sure you are in the directory that you are working in mine is /Applications/MAMP/htdocs

$ cd /Applications/MAMP/htdocs

Next you need to download all Wordpress files

$ wp core download --path=DIRECTORY_NAME
I’m using the directory name demo

Now change to the directory you set up mine is “cd demo”

Now you need to run the following command. This gives the WP CLI access to your MAMP bin files so its able to created Databases for you.

$ export PATH=$PATH:/Applications/MAMP/Library/bin/

Next you set up the WP-Config file with the following. Please make sure your MAMP is running.

$ wp config create --dbname=DATABASE_NAME --dbuser=root --dbpass=root

If you have set up a virtual host you will need to use the a different command. This will use the dbhost as your local IP not localhost!

$ wp config create --dbname=demo --dbuser=root --dbpass=root --dbhost=127.0.0.1
All going well this is what you should see!

Now run

$ wp db create

All going well you should see the following

The final command to run to install Wordpress and add a username / password and email.

$ wp core install --url=localhost/demo --title=”Demo Title” --admin_user=admin --admin_password=password --admin_email=test@example.com

Please change all fields do what you want for your Wordpress set up.

Wordpress installed successfully!

You will now be able to login and all of your files and database has been created for you! There’s a lot more you can do with WP CLI this is only installing the core and installing the database but you can update plugins/ update core and more! Check it out here.

If you have any issues will comment below and let me know!

--

--