Skip to content

Instantly share code, notes, and snippets.

@chrisjordanme
Last active October 28, 2017 18:40
Show Gist options
  • Save chrisjordanme/b416b963e58a3cca14593b1f5c7cab8c to your computer and use it in GitHub Desktop.
Save chrisjordanme/b416b963e58a3cca14593b1f5c7cab8c to your computer and use it in GitHub Desktop.
An opinionated bash function to expedite the installation and configuration of new WordPress sites in a local development environment. The script clones a fork of Mark Jaquith's WordPress Skeleton project, pulls in WordPress as a submodule, then writes the local-config file while also creating a new local MySQL database and sets up user perms.
# WordPress fast local installation to kickstart new sites fast. This uses a fork of Mark Jaquith's WP Skeleton as the foundational structure of the WP install.
function wpinstall() {
# Go get all the things
git clone [email protected]:chrisjordanme/WordPress-Skeleton.git;
cd WordPress-Skeleton/wp;
git submodule init && git submodule update;
# Collect inputs needed for installation/config
echo "Success! WordPress has successfully been installed. Now tell me, what is the name of your new database that this site will need?";
read dbnew;
echo "What is the name of your new database user?";
read dbuser;
echo "... and what should this new database user's password be?";
read dbuserpwd;
cd ..;
echo "And finally, your system level MySQL password?";
read rootpwd;
# Write to the local-config from wp-skeleton
cp ./local-config-sample.php ./local-config.php;
sed -i -e "s/local_db_name/${dbnew}/g" ./local-config.php;
sed -i -e "s/local_db_user/${dbuser}/g" ./local-config.php;
sed -i -e "s/local_db_password/${dbuserpwd}/g" ./local-config.php;
# Create new database and user
mysql -u root -p${rootpwd} -e "CREATE DATABASE ${dbnew};"
mysql -u root -p${rootpwd} -e "CREATE USER '${dbuser}'@'localhost' IDENTIFIED BY '${dbuserpwd}';"
mysql -u root -p${rootpwd} -e "GRANT ALL PRIVILEGES ON ${dbnew}.* TO '${dbuser}'@'localhost';"
mysql -u root -p${rootpwd} -e "FLUSH PRIVILEGES;"
# Remove the -e file created by sed
rm -rf ./local-config.php-e;
ls -a;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment