Skip to content

Instantly share code, notes, and snippets.

@WPprodigy
Created December 21, 2019 08:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WPprodigy/2ceeeaf631a56ad9c3dd4498813f227e to your computer and use it in GitHub Desktop.
Save WPprodigy/2ceeeaf631a56ad9c3dd4498813f227e to your computer and use it in GitHub Desktop.
WP local site creation script. Made for use with https://laravel.com/docs/6.x/valet
#!/bin/bash
# Usage: wp-create sitename
if [ $# -eq 0 ]; then
echo "Need to provide the directory name to be created."
exit 1
fi
# set up new folder to house the WP install
cd ~/development/valet-sites
mkdir $1 && cd $1
# dowload wordpress and setup to use new database
wp core download
wp config create --dbname=$1 --dbuser=root --dbpass=''
wp config set WP_DEBUG true --raw --type=constant
wp config set WP_DEBUG_DISPLAY false --raw --type=constant
wp config set WP_DEBUG_LOG true --raw --type=constant
wp config set SCRIPT_DEBUG false --raw --type=constant
wp config set JETPACK_DEV_DEBUG true --raw --type=constant
wp db create
wp core install --url=$1.test --title=$1 --admin_user=a --admin_email=local@localhost.local --admin_password=p
echo -e "Success: $1.test created."
# make https, will ask for a pw and restart the server
echo -e "Note: Enter your password so we can secure the site with a local SSL cert:"
valet secure $1
# delete Hello Dolly & Akismet
wp plugin delete hello
wp plugin delete akismet
# install and activate Query Monitor
wp plugin install query-monitor && wp plugin activate query-monitor
# open the site in default browser
valet open $1
@WPprodigy
Copy link
Author

WPprodigy commented Dec 21, 2019

Requires a local development environment. I use https://laravel.com/docs/6.x/valet, and ~/development/valet-sites is where I've run valet park.

Usage:

  1. Download script, and make it executable: chmod 755 /location/to/wp-create
  2. Ensure script location is in your current PATH. Run echo $PATH to see where you could put it. /usr/local/bin is a good option, else you can put anywhere and add to your PATH's if you know how.
  3. Change ~/development/valet-sites in the script to wherever you want sites to be added.
  4. Run wp-create sitename to have sitename.test automatically created for you, opened in the browser, with the username a and password p.

@WPprodigy
Copy link
Author

Also pairs well with wp-remove script below for deleting the sites :)

#!/bin/bash

if [ $# -eq 0 ]; then
    echo "Need to provide the directory to be removed."
    exit 1
fi

# go to the valet sites folder
cd ~/development/valet-sites/$1

# remove the database
wp db drop --yes

# trash the folder
trash ~/development/valet-sites/$1

echo -e "Success: $1.test site removed."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment