Skip to content

Instantly share code, notes, and snippets.

@rnevius
Created October 11, 2014 16:37
Show Gist options
  • Save rnevius/2c81c22bc7e2620a9f9b to your computer and use it in GitHub Desktop.
Save rnevius/2c81c22bc7e2620a9f9b to your computer and use it in GitHub Desktop.
Shell / SSH WordPress Installer
#!/bin/bash -e
clear
echo ""
echo "============================================="
echo "# #"
echo "# Welcome to the WordPress Installer #"
echo "# #"
echo "============================================="
echo ""
read -e -p "Database Name: " db_name
read -e -p "Database User: " db_user
read -e -p "Database Password: " db_pass
echo ""
read -e -p "Ready to Rock? (y/n): " run
if [ "$run" == n ]
then
echo "Bye..."
exit
else
echo ""
echo "============================================"
echo "# Installing WordPress #"
echo "============================================"
echo ""
# Download, extract, and delete the latest, compressed version of WordPress
wget http://wordpress.org/latest.tar.gz
tar -xzvf latest.tar.gz --strip-components=1
rm latest.tar.gz
# Let's copy the first part of wp-config-sampe.php and start piecing together wp-config.php
grep -F -B1015 -A1 "@since 2.6.0" wp-config-sample.php > wp-config.php
# Set database details with perl find and replace
perl -pi -e "s/database_name_here/$db_name/g" wp-config.php
perl -pi -e "s/username_here/$db_user/g" wp-config.php
perl -pi -e "s/password_here/$db_pass/g" wp-config.php
# Use the WordPress.org secret-key service to download a set of secret keys
# Save it in a file named keys.salt
wget https://api.wordpress.org/secret-key/1.1/salt/ -O keys.salt
# Append the authorization keys to the wp-config.php file
cat keys.salt >> wp-config.php
# Get rid of the keys file
rm keys.salt
# Finish building the config file by appending the last part of wp-config-sample.php
grep -F -B1 -A1015 "/**#@-*/" wp-config-sample.php >> wp-config.php
echo ""
echo "============================================"
echo "# Hardening WordPress #"
echo "============================================"
echo ""
# Set the appropriate directory permissions
find -type d -exec chmod 755 {} \;
# Set the appropriate file permissions
find -type f -exec chmod 644 {} \;
# Set wp-config.php to 440. This is commented out, because it may break some configurations.
# Uncomment at your own risk.
# chmod 440 wp-config.php
echo ""
echo "============================================"
echo "# Cleaning Up #"
echo "============================================"
echo ""
# Deletes the currently-running script (self)
rm ${0##*/}
# Get rid of the crap default themes...leaving one for fallback
rm -rf wp-content/themes/twentyfourteen || true
rm -rf wp-content/themes/twentythirteen || true
# Get rid of bogus plugins
rm -rf wp-content/plugins/akismet || true
rm wp-content/plugins/hello.php || true
clear
echo ""
echo "============================================"
echo "# WordPress installation complete! #"
echo "# --- #"
echo "# Stay classy, WordPress nerds #"
echo "============================================"
echo ""
fi
@rnevius
Copy link
Author

rnevius commented Oct 11, 2014

To run this installer:

  1. Log into your server via SSH
  2. Create a database and make note of the database name and user
  3. Create / navigate to your desired WordPress root directory (for example, /var/www/html/blog)
  4. Copy and paste the attached snippet into your SSH client.
  5. Follow the on-screen instructions.

wget https://gist.githubusercontent.com/rnevius/2c81c22bc7e2620a9f9b/raw/wp-installer.sh && chmod 555 wp-installer.sh && ./wp-installer.sh

@rnevius
Copy link
Author

rnevius commented Oct 11, 2014

Also, if you'd rather input your database info in the WordPress installer, rather than the shell, you can use the following (completely avoids using the above shell script):

wget http://wordpress.org/latest.tar.gz && tar -xzvf latest.tar.gz --strip-components=1 && rm latest.tar.gz && rm -rf wp-content/themes/twentyfourteen ; rm -rf wp-content/themes/twentythirteen ; rm -rf wp-content/plugins/akismet ; rm -rf wp-content/plugins/hello.php ; find -type d -exec chmod 755 {} \; && find -type f -exec chmod 644 {} \;

The above snippet does everything the shell script does, minus the configuration of wp-config.php.

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