Skip to content

Instantly share code, notes, and snippets.

@RatulHasan
Created December 15, 2022 05:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RatulHasan/0b9cc76387663c59ecc946a2d3aef344 to your computer and use it in GitHub Desktop.
Save RatulHasan/0b9cc76387663c59ecc946a2d3aef344 to your computer and use it in GitHub Desktop.
Automate WP fresh installation
#!/bin/bash -e
clear
# for MAMP user using php version 7.1.1 this is required
# export PATH="/Applications/MAMP/bin/php/php7.1.1/bin:$PATH"
# Remove/Uninstall process
if [[ $1 == "remove" ]]; then
# Grab the project name
if [[ -z $2 ]]; then
echo "WP Project to remove: "
read -e projectname
else
projectname=$2
fi
projectDirectory="$projectname"
if [[ ! -d $projectDirectory ]]; then
echo "$projectDirectory directory not exists"
exit
fi
wp db drop --yes --path=$projectDirectory
rm -rf $projectDirectory
echo "$projectname removed completely"
exit
fi
echo "================================================================="
echo "WordPress Installer!!"
echo "================================================================="
if [ -z "$1" ]; then
# accept user input for the databse name
echo "Project Name(no space): "
read -e projectname
else
projectname=$1
fi
mkdir -p "$projectname"
cd "$projectname"
# download the WordPress core files
wp core download
# create the wp-config file with our standard setup
wp core config --dbname=$projectname --dbuser=root --dbpass=root --extra-php <<PHP
define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
define( 'SCRIPT_DEBUG', true );
PHP
# create database, and install WordPress
wp db create
wp core install --url="$projectname.test" --title="WordPress Localhost Site" --admin_user="admin101" --admin_password="admin101" --admin_email="admin@mail.com" --skip-email
# discourage search engines
wp option update blog_public 0
# this is required for the .htaccess
touch wp-cli.local.yml
echo "apache_modules:
- mod_rewrite
" > wp-cli.local.yml
# set pretty urls
wp rewrite structure '/%postname%/' --hard
wp rewrite flush --hard
# set timezone
wp option update timezone_string "Asia/Dhaka"
rm wp-cli.local.yml
# delete akismet and hello dolly
wp plugin delete akismet
wp plugin delete hello
# install starter theme
# if [ ! -z "$2" ]; then
# wp theme install ~/epsilon.zip --activate
# fi
echo "================================================================="
echo "Installation is complete. open browse $projectname.test/wp-admin/"
echo "Admin User: admin101"
echo "Admin Pass: admin101"
echo "================================================================="
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment