Skip to content

Instantly share code, notes, and snippets.

@trepmal
Created September 20, 2012 00:11
Show Gist options
  • Save trepmal/3753153 to your computer and use it in GitHub Desktop.
Save trepmal/3753153 to your computer and use it in GitHub Desktop.
[bash] Download WordPress, setup database, configure, launch
#!/bin/bash
## > ./wp.sh sitename mysqluser userpassword
## sitename: directory the site will located in
## mysqluser: user and database name
## userpassword: mysql user's password
## ex: ./wp.sh testsite tester 7n5nSmg15X5s
xampp='/Applications/XAMPP/xamppfiles/htdocs/'
# Create directory
mkdir $xampp$1
cd $xampp$1
# Download latest stable version of WordPress
curl -O http://wordpress.org/latest.tar.gz
# Extract
tar -xf latest.tar.gz
cd $xampp$1/wordpress/
# Insert creds into wp-config.php
mv wp-config-sample.php wp-config.php
sed -i '' "s/username_here/$2/g" wp-config.php
sed -i '' "s/password_here/$3/g" wp-config.php
sed -i '' "s/database_name_here/$2/g" wp-config.php
# Optionally, turn debug on
# sed -i '' "s/'WP_DEBUG', false/'WP_DEBUG', true/g" wp-config.php
# Create database and user
q1="CREATE DATABASE $2;"
q2="USE $2;"
q3="GRANT ALL PRIVILEGES ON $2.* TO '$2'@'localhost' IDENTIFIED BY '$3';"
q4="FLUSH PRIVILEGES;"
SQL="${q1}${q2}${q3}${q4}"
/Applications/XAMPP/xamppfiles/bin/mysql -uroot -e "$SQL"
# Clean up
mv $xampp$1/wordpress/* $xampp$1/
rm $xampp$1/latest.tar.gz
rmdir $xampp$1/wordpress
# Open in Chrome, choose the one that works for your setup :)
# open http://localhost/$1 -a '/Applications/Google Chrome.app'
open http://local.dev/$1 -a '/Applications/Google Chrome.app'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment