Skip to content

Instantly share code, notes, and snippets.

@beardedinbinary
Last active October 22, 2024 05:56
Show Gist options
  • Save beardedinbinary/79d7ad34f9980f0a4c23 to your computer and use it in GitHub Desktop.
Save beardedinbinary/79d7ad34f9980f0a4c23 to your computer and use it in GitHub Desktop.
Automated Wordpress Install Script
#!/bin/bash
# Install script for Latest WordPress on local dev
# Setup
# Hardcoded variables that shouldn't change much
# Path to MySQL
MYSQL='/usr/bin/mysql'
# DB Variables
echo "MySQL Host:"
read mysqlhost
export mysqlhost
echo "MySQL DB Name:"
read mysqldb
export mysqldb
echo "MySQL DB User:"
read mysqluser
export mysqluser
echo "MySQL User Password:"
read mysqlpass
export mysqlpass
# WP Variables
echo "Site Title:"
read wptitle
export wptitle
echo "Admin Username:"
read wpuser
export wpuser
echo "Admin Password:"
read wppass
export wppass
echo "Admin Email"
read wpemail
export wpemail
# Site Variables
echo "Site URL (ie, www.youraddress.com):"
read siteurl
export siteurl
echo "You will now be prompted for your MySQL password"
# Setup DB & DB User
$MYSQL -uroot -p$mysqlrootpass -e "CREATE DATABASE IF NOT EXISTS $mysqldb; GRANT ALL ON $mysqldb.* TO '$mysqluser'@'$mysqlhost' IDENTIFIED BY '$mysqlpass'; FLUSH PRIVILEGES "
# Download latest WordPress and uncompress
wget http://wordpress.org/latest.tar.gz
tar zxf latest.tar.gz
mv wordpress/* ./
# Build our wp-config.php file
sed -e "s/localhost/"$mysqlhost"/" -e "s/database_name_here/"$mysqldb"/" -e "s/username_here/"$mysqluser"/" -e "s/password_here/"$mysqlpass"/" wp-config-sample.php > wp-config.php
# Grab our Salt Keys
SALT=$(curl -L https://api.wordpress.org/secret-key/1.1/salt/)
STRING='put your unique phrase here'
printf '%s\n' "g/$STRING/d" a "$SALT" . w | ed -s wp-config.php
# Run our install ...
curl -d "weblog_title=$wptitle&user_name=$wpuser&admin_password=$wppass&admin_password2=$wppass&admin_email=$wpemail" http://$siteurl/wp-admin/install.php?step=2
# Tidy up
rmdir wordpress
rm latest.tar.gz
rm wp-config-sample.php
# Download starkers
cd wp-content/themes/
wget https://github.com/viewportindustries/starkers/archive/master.zip
unzip master.zip
rm master.zip
@jessuppi
Copy link

jessuppi commented Jul 5, 2019

Hey Steve! Just FYI we referenced your script in our SlickStack project under ss-install along with a few others that have helped inspire some of our Bash command formatting... anyway cheers dude: https://github.com/littlebizzy/slickstack

@buildwithmh
Copy link

Thank you so much for sharing this Steve! it's really informative.

@cwegener
Copy link

Nice and simple script!

You're not checking for the successful execution of the install.php script.

WP will return a HTTP 500 error on failure of the install.php, which needs to be caught by curl with curl's curl --fail option.

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