Skip to content

Instantly share code, notes, and snippets.

@Mamaduka
Last active March 27, 2021 08:36
Show Gist options
  • Save Mamaduka/74ee389cea8c9b469ab485071880a885 to your computer and use it in GitHub Desktop.
Save Mamaduka/74ee389cea8c9b469ab485071880a885 to your computer and use it in GitHub Desktop.

Local dev environment with Valet/DBngin on Apple Silicon

Setup

#!/bin/sh
# Sell script for creating WP sites with Valet.
# Based on https://jeremy.hu/dev-environment-laravel-valet-wp-cli/.
set -e
cd ~/Projects
BLUE_BOLD='\033[1;34m';
GREEN_BOLD='\033[1;32m';
RED_BOLD='\033[1;31m';
YELLOW_BOLD='\033[1;33m';
COLOR_RESET='\033[0m';
# Enable nicer messaging.
error () {
echo "${RED_BOLD}$1${COLOR_RESET}"
}
status () {
echo "${BLUE_BOLD}$1${COLOR_RESET}"
}
success () {
echo "${GREEN_BOLD}$1${COLOR_RESET}"
}
warning () {
echo "${YELLOW_BOLD}$1${COLOR_RESET}"
}
status "➤ What do you want your site to be called? No Spaces, just lowercase letters please."
read site_name
mkdir $site_name
cd $site_name
status "➤ Link the current working directory to Valet."
valet link
status "➤ Creating database..."
echo "CREATE DATABASE $site_name" | mysql -h127.0.0.1 -uroot
status "➤ Installing WordPress..."
wp core download
wp config create --dbname=$site_name --dbuser=root --dbpass='' --dbhost=127.0.0.1 --extra-php <<PHP
define( 'WP_DEBUG', true );
if ( WP_DEBUG ) {
@error_reporting( E_ALL );
@ini_set( 'log_errors', true );
@ini_set( 'log_errors_max_len', '0' );
define( 'WP_DEBUG_LOG', true );
define( 'WP_DEBUG_DISPLAY', false );
define( 'CONCATENATE_SCRIPTS', false );
define( 'SAVEQUERIES', false );
}
PHP
# Change admin user/pass as needed.
wp core install --url=$site_name.test --title=$site_name --admin_user=admin --admin_password=password --admin_email=admin@valet.test --skip-email
# Delete inactive plugins. Akismet and Hello Dolly.
wp plugin delete $(wp plugin list --field=name)
status "➤ Secure with TLS (y/n)?"
read answer
if [ "$answer" != "${answer#[Yy]}" ] ;then
valet secure $site_name
fi
success "✓ Excellent. Your new site is ready! URL: http://$site_name.test/wp-admin/"
exit 0;
#!/bin/sh
# A shell script to delete a site.
# Based on https://jeremy.hu/dev-environment-laravel-valet-wp-cli/.
echo "Which site do you want to delete?"
read site_name
# Change this to a directory where your sites live.
cd ~/Projects
valet unlink $site_name
rm -rf $site_name
# Delete the matching database table.
echo "DROP DATABASE IF EXISTS $site_name" | mysql -h127.0.0.1 -uroot
exit 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment