Skip to content

joshmckibbin/wp-create

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 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:

  • Apache with mod_rewrite enabled
  • MariaDB 10.6+ with root access
  • PHP 8.2+ with the curl, imagick, json, intl, mbstring, mysql, xml and zip extensions installed.
  • wp-cli (The wp-create.sh script will attempt to install it if it isn't installed)

Installing the prerequisites

With root access, run the following:

apt update && apt install -y apache2 && systemctl enable apache2 && \
a2enmod rewrite && systemctl restart apache2 && \
apt install -y mariadb-server && mariadb-secure-installation && \
apt install -y php php-curl php-imagick php-json php-intl php-mbstring php-mysql php-xml php-zip && \
systemctl restart apache2

Set a root password for MariaDB when asked if you want to change the root password. It should be the same value as DB_ROOT_PASS in the .env file.

Note: If http://localhost will not resolve after installation in WSL2, you may need to disable Fast Startup in your Windows settings and reboot your computer.

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 git@github.com: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?

Note: If your development directory (DEV_DIR) is within your home folder (which is the default), you will need to add executable permissions to your home folder:

chmod o+x $HOME

Optional: Add the script as a bash alias

echo "alias wp-create='$HOME/dev/wp-create/wp-create.sh'" >> ~/.bash_aliases

Now you can call the script from anywhere within Ubuntu:

wp-create "My Great WordPress Site"

License

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

About

Create and Destroy local WordPress sites in Ubuntu

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages