Skip to content

Instantly share code, notes, and snippets.

@yanbab
Last active December 16, 2017 17:53
Show Gist options
  • Save yanbab/d801abfd48ce0e2933b0a6c955e546e6 to your computer and use it in GitHub Desktop.
Save yanbab/d801abfd48ce0e2933b0a6c955e546e6 to your computer and use it in GitHub Desktop.
Bootstraps a fully working WordPress install in one command
#!/bin/sh
#
# Usage: 'wp-create.sh site_name [site_url]'
#
# Creates 'site_name' database, user and WordPress install
#
# Note : On MacOS you may need to fix mysql with
# export PATH=/usr/local/mysql/bin:$PATH
# sudo mkdir /var/mysql && sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock
#
PRJ=$1
URL="http://localhost/Clients/${PRJ}"
MAIL="contact@$PRJ.com"
PLUGINS="elementor contact-form-7"
THEMES="astra"
LOCALE="fr_FR"
MYSQL_HOST="localhost" # localhost
MYSQL_USER="root"
MYSQL_PASS= # empty to ask
WWW_USER="_www:_www" # _www on MacOS, www_data on Ubuntu
if [[ $# -eq 0 ]] ; then
echo "Usage: '$0 site_name [site_url]' creates 'site_name' database, user and WordPress install"
exit 1
fi
#
# MySQL
#
MYSQL="mysql -u$MYSQL_USER -p$MYSQL_PASS -e "
# Create mysql user and database
SQL="CREATE USER '$PRJ'@'$MYSQL_HOST' IDENTIFIED BY '$PRJ';"
#SQL="$SQL GRANT USAGE ON *.* TO '$PRJ'@'localhost';"
SQL="$SQL CREATE DATABASE IF NOT EXISTS \`$PRJ\`;"
SQL="$SQL GRANT ALL PRIVILEGES ON \`$PRJ\`.* TO '$PRJ'@'$MYSQL_HOST';"
echo "> $SQL"
if $MYSQL "$SQL"; then
echo "> Success !"
else
echo "> Query failed :("
exit
fi
#
# Wordpress
#
if mkdir $PRJ; then
cd $PRJ
echo "Installing wordpress"
else
echo "Install failed : folder '$PRJ' already exists"
exit
fi
# Download and setup wordpress
wp core download --locale=$LOCALE
wp core config --dbname=$PRJ --dbuser=$PRJ --dbpass=$PRJ --dbhost=$MYSQL_HOST --extra-php="define('FS_METHOD', 'direct');\n"
wp core install --url=$URL --title="$PRJ" --admin_user=$PRJ --admin_password=$PRJ --admin_email="$MAIL"
# Install plugins
wp plugin uninstall hello
wp plugin install $PLUGINS --activate
# Install themes
wp theme install $THEMES --activate
wp theme uninstall twentyfifteen twentysixteen twentyseventeen
# Options
#wp option update permalink_structure "/%year%/%monthnum%/%day%/%postname%/" # removes 'index.php/' from urls
# Fix permissions
cd ..
chmod -R og+w $PRJ/wp-content
#sudo chown -R _www:_www $PRJ
#
# Show result
#
echo ""
echo "MySQL dbname: $PRJ"
echo "MySQL user: $PRJ"
echo "MySQL pass: $PRJ"
echo "MySQL host: $MYSQL_HOST"
echo "WP user: $PRJ"
echo "WP password: $PRJ"
echo "WP email: $MAIL"
echo "WP path: $PWD"
echo "WP url: $URL"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment