I’m sure you’ll agree that it is important to build and work on sites in a staged environment before putting them live. Even though we don’t always follow this advice (quick fixes don’t always warrant the effort of syncing to a local environment), it is an important habit to adopt.
The only problem here is that it is time-consuming. It’s not going to take hours but, it takes enough time to be an inconvenience.
I’m always on the lookout for new tools to speed up my workflow. For example, when migrating sites, I use duplicator as it makes the process smoother and quicker. So, when it comes to building a new website locally, I have a powerful tool that makes the process a breeze.
I prefer to do as much of my work as possible from the command line. There’s a lot less reaching for the mouse that way. It just so happens that there is a tool that mashes WordPress and the command line together. WP-CLI (WordPress Command Line Interface). There are so many jobs you can do using this helpful tool. What I’m going to show you today, is how to install WordPress locally using this tool.
Make a folder for your new site
I’m going to assume you know at least a little bit about command-line while doing this (fire a comment below if you need me to clarify any of the commands). We need to make a new folder for our new WordPress install. I use a Mac therefore, I use MAMP to serve my WordPress sites locally. If you are using windows check out WAMP. We need to go to the folder that MAMP uses to store websites. By default, it is located in:
unless you have explicitly changed it. Change it to that directory
Next, we need to create a new folder.
Then move into the newly created directory.
Now the fun begins.
Download WordPress in a flash
This is the easiest part by far. Type the command below into your terminal (or copy and paste, your choice).
wp core download
Before your eyes, you will see WordPress installing into your newly created directory.
Create the config file and database.
The next step is to create you wp config file
create --dbname="name of your database" --dbuser="root" --dbpass="root"
You can call your database whatever you’d like. It doesn’t exist yet. Let’s create it
wp db create
You have now created a WordPress database in seconds. No stuffing around with MySQL or phpmyadmin required.
The famous 5 minute install done in less than a minute!
Now we have to install WordPress. I often forget parts of this one but here is a little tip I picked up. By typing
wp core install you will receive an error message. However, contained in that error message are all the missing parameters you will need.
wp core install --title="Name of your site" --url="path to your site" --admin_user="user" --admin_password="password" --admin_email="firstname.lastname@example.org"
Congratulations, you have now installed a new WordPress website locally. It only took 4 commands total. Pretty neat huh!
WP CLI is an amazing tool with a heap of different functions that it can perform. If you do nothing with it other than installing WordPress sites locally it is worth the effort to install it alone. I challenge you to delve a bit deeper and find out what else you can do with this tool. Leave a comment below and tell me what you discover. I will be writing a lot more about WP CLI in the future, so stay tuned for more tricks.