This repository contains shell scripts designed to automate the creation and removal of local WordPress sites running on Ubuntu.
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.shscript will attempt to install it if it isn't installed)
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 apache2Set 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.
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-cliif necessary - Downloads the latest version of WordPress
- Creates the wp-config.php file
- Creates the database user
DB_USERif 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_NAMEtoDB_USER - Installs WordPress with a database tables prefix of 'wp_
DB_NAME_' - Checks
DB_DUMP_DIRfor an existing database dump file and imports it. In this order:SLUG-dev.sqlSLUG.sqlSLUG-prod.sql
- If
SMTP_USERandSMTP_PASSare set, it installs and activates the Simple SMTP Mailer plugin.
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
SLUGand 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
- 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- Clone (or download and extract) the repository into the directory
git clone git@github.com:joshmckibbin/wp-create.git .- Make sure you have execute permissions for the scripts
chmod +x wp-create.sh wp-destroy.sh- Copy the
.env-samplefile to.envand replace the environment values with your own.
cp .env-sample .env- Run one of the shell scripts
./wp-create.sh- 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 $HOMEecho "alias wp-create='$HOME/dev/wp-create/wp-create.sh'" >> ~/.bash_aliasesNow you can call the script from anywhere within Ubuntu:
wp-create "My Great WordPress Site"This project is licensed under the MIT License. See the LICENSE file for details.