Skip to content

joshmckibbin/wp-create

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WP-Create

This repository contains shell scripts designed to automate the creation and removal of local WordPress sites running on Ubuntu.

Prerequisites

Ubuntu (or Ubuntu running on WSL2) with:

  • PHP 8.2+ with the curl, dom, gd, json, mbstring, mysqli, openssl, xml, zip modules enabled
  • Apache with mod_rewrite enabled
  • MariaDB 10.6+ with root access
  • wp-cli (The wp-create.sh script will attempt to install it if it isn't installed)

Scripts

wp-create.sh

This script uses set variables in an .env file to automate the creation of local WordPress sites.
See the sample .env file

It prompts for a TITLE and a SLUG. If no TITLE is provided, it defaults to 'WordPress'. If no SLUG is provided, it defaults to generating a SLUG from the TITLE truncated to a maximum of 15 characters.
It then performs the following functions:

  • Creates the necessary directory structure at 'DEV_DIR/SLUG/wordpress'
  • Installs wp-cli if necessary
  • Downloads the latest version of WordPress
  • Creates the wp-config.php file
  • Creates the database user DB_USER if they do not already exist
  • Creates a new database with a name generated by replacing the dashes in the 'SLUG' with underscores (DB_NAME)
  • Grants all permissions for DB_NAME to DB_USER
  • Installs WordPress with a database tables prefix of 'wp_DB_NAME_'
  • Checks DB_DUMP_DIR for an existing database dump file and imports it. In this order:
    • SLUG-dev.sql
    • SLUG.sql
    • SLUG-prod.sql
  • If SMTP_USER and SMTP_PASS are set, it installs and activates the Simple SMTP Mailer plugin.

wp-destroy.sh

This script removes everything and should be used with extreme caution.

Removes a WordPress site created by running the wp-create.sh script:

  • Prompts for the site's SLUG and then asks for confirmation of deletion
  • Asks if you want to delete the site's database
  • Asks if you want to delete the Apache config file

Usage

  1. Create and/or navigate to the directory where you want to create WordPress sites (Should be the same as DEV_DIR)
mkdir -p /path/to/dev/directory && cd /path/to/dev/directory
  1. Clone (or download and extract) the repository into the directory
git clone [email protected]:joshmckibbin/wp-create.git .
  1. Make sure you have execute permissions for the scripts
chmod +x wp-create.sh wp-destroy.sh
  1. Copy the .env-sample file to .env and replace the environment values with your own.
cp .env-sample .env
  1. Run one of the shell scripts
./wp-create.sh
  1. Profit?

License

This project is licensed under the MIT License. See the LICENSE file for details.