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:
- Download Latest WordPress Zip
- Extract files
- Create MySQL DB
- Configure wp-config.php file
- 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.