Skip to content

Instantly share code, notes, and snippets.

@robbintt
Created June 16, 2014 22:58
Show Gist options
  • Save robbintt/42cae9707c0d065bed81 to your computer and use it in GitHub Desktop.
Save robbintt/42cae9707c0d065bed81 to your computer and use it in GitHub Desktop.
Install WordPress, MySQL DB, Roots.
#!/bin/bash
: '
Complete command line script for a new wordpress install.
You must still build an APACHE VIRTUALHOST
$ ./getwp.sh example.taui.io ex-admin
Arguments:
1 - webpage, example.taui.io
run this from public/ -- the resulting directory will be: public/example.taui.io
'
# Must have a command line argument
if [ $# -eq 0 ]; then
echo "ERROR: No arguments provided"
exit 1
fi
website=$1
public_path="/home/www/public"
cd $public_path
mkdir $website
cd $website
wget https://wordpress.org/latest.tar.gz
tar -xzvf latest.tar.gz
rm latest.tar.gz
mv wordpress www
cd www
# for apache
mkdir logs
touch logs/error.log
touch logs/access.log
projectname=$(echo $website | sed -e "s/\.//g")
git clone git@github.com:roots/roots.git ./wp-content/themes/$projectname
# user same as project name
dbuser=$(echo $website | sed -e "s/\.//g")
dbpass=$(pwgen -cn 12 1)
sqlcommands='CREATE DATABASE '$projectname'; GRANT ALL PRIVILEGES ON '$projectname'.* TO "'$dbuser'"@"localhost" IDENTIFIED BY "'$dbpass'"; FLUSH PRIVILEGES'
echo $sqlcommands
mysql -h localhost -u root -p -e "$sqlcommands"
mv wp-config-sample.php wp-config.php
sed -i 's/database_name_here/'$projectname'/g' wp-config.php
sed -i 's/username_here/'$dbuser'/g' wp-config.php
sed -i 's/password_here/'$dbpass'/g' wp-config.php
unset website
unset projectname
unset dbuser
unset dbpass
: ' do the salting manually right now
list=$(curl -s https://api.wordpress.org/secret-key/1.1/salt/)
# This line is very sensitive to changes in wp-config.php
while read -r line; do
sed '0,/RE/.*put your unique phrase here.*//'$line'/' wp-config.php
done <<< "$list"
'
echo ***
echo *** YOU MUST MANUALLY ADD SALTS TO YOUR wp-config.php !!!
echo ***
echo *** PLEASE MANUALLY CHANGE PARENT_DIR PERMISSIONS TO www-data:www-data
echo *** THEN CREATE AN APPROPRIATE SYMLINK FOR THE PARENT_DIR
echo *** FINALLY ADD THE SITE TO SITES AVAILABLE AND SITES ENABLED
echo *** \(and restart apache\)
echo ***
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment