Home » WordPress Development » Creating a new WordPress site via the command line

Creating a new WordPress site via the command line

At The Code Company, we work with a couple of different groups of clients. One of those groups are the smaller business sites, smaller, simpler WordPress sites that we don’t put on version control, and usually turn around quite quickly.

Automation is also a big passion of mine, I hate doing the same thing over and over again.

With all these small sites we’ve built over the years, I wanted a way to speed up the creation of setting up a blank development site and what not. I had created a bash script that essentially did the following:

  1. Download Latest WordPress Zip
  2. Extract files
  3. Create MySQL DB
  4. Configure wp-config.php file
  5. Copy some plugins over ready to activate

That was pretty good. Saved about 10-15 minutes.

A few weeks back I accidentally deleted that script, so I thought it was time to re-do it, but this time I wanted to use WP-CLI, as it has a heap more power under the hood than a bash file.

What I created was a script I run on my development server in the office. It creates the MySQL database, creates the config, downloads WordPress, and fixes the permissions so it works for anyone on FTP.

Yes, permissions are not standard, but this is just because it’s on dev. When we move to production, we set the permissions correctly.

I couldn’t find anything that was exactly what I’m looking for, so the file below may be of some help, who knows!

All I have to do is specify a “siteslug” and a “site title” via the command and the site is installed, and important plugins installed, site is installed and what not. I really do love WP-CLI.

Ben May

Ben is Managing Director of The Code Company. He is passionate about working with publishers on clever and innovative ways to solve complex problems. He works with The Code Company team on all projects, bringing his perspective and problem solving skills to deliver great outcomes.

Do you work in digital media or publishing? Join our newsletter.

If you've made it this far on one of our posts, you're probably someone who'd find value in our email newsletter where we send analysis, insights and curated links for the digital publishing and media world. You can subscribe below and opt out any time.