I’m sure you’ll agree that it is important to build and work on sites in a staged enviroment before putting them live. Even though we don’t always follow this advice (quick fixes don’t always warrent the effort of syncing to a local enviroment), it is an important habbit.
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 inconviniece.
I’m always on the look out 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.
I’m going to throw you over to the official docs for this one. Head over and get it installed on your machine (I reccomend taking a look at getting autocomplete setup as well as this will save you a lot of time in the long run.
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 you it is located in
unless you have explicitly changed it. Change into 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 downlaod
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 databse
" --dbuser="root" --dbpass="root"
You can call your database whatever you’d like. It doesn’t exist yet. Lets create it
You have now created a WordPress database in seconds. No stuffing around with mysql or phpmyadmin required.
Last step. 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 litle tip I picked up. By typing
wp core install you will recieve 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 preform. 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.