Skip to content

Instantly share code, notes, and snippets.

@hermpheus
Forked from scottlee/GetWP
Created July 5, 2012 20:33
Show Gist options
  • Save hermpheus/3056262 to your computer and use it in GitHub Desktop.
Save hermpheus/3056262 to your computer and use it in GitHub Desktop.
Ubuntu LAMP: Create WordPress install, apache, hosts, etc
#!/bin/bash
##########
## Setup: hardcode your mysql user/pass. Yeah, yeah, I know...it's frowned upon.
## but for local development, I have no problem with it.
## Find and replace: MYSQLUSER / MYSQLPASS
##
## Usage: This script accepts only one variable, the site name.
##
#########
# Create working folder
mkdir /tmp/getWP
cd /tmp/getWP
## Download latest (stable) version of WordPress
curl -O http://wordpress.org/latest.tar.gz
## Uncompress
tar -xf latest.tar.gz
cd /tmp/getWP/wordpress/
## Edit wp-config
mv wp-config-sample.php wp-config.php
sed -i "s/username_here/MYSQLUSER/g" wp-config.php
sed -i "s/password_here/MYSQLPASS/g" wp-config.php
sed -i "s/database_name_here/$1/g" wp-config.php
## Add to Apache config
sudo sed -i "$ a \
\n<VirtualHost 127.0.0.1> \n\n\
\
DocumentRoot /var/www/$1/ \n\
ServerName $1.localhost.com \n\
ServerAlias $1.localhost.com \n\
ServerAdmin admin@$1.localhost.com \n\
\n\
</VirtualHost>\n" /etc/apache2/sites-available/default
## add to hosts
sudo sed -i "$ a \
\n127.0.0.1 $1.localhost.com \n\
" /etc/hosts
## Create Database
CMD="create database $1"
/usr/bin/mysql --host=localhost -uMYSQLPASS -pMYSQLUSER -e "$CMD"
## Move working folder to ~/Sites
mv /tmp/getWP/wordpress /var/www/$1
## restart apache...
sudo service apache2 restart
## Open in Chrome
google-chrome http://$1.localhost.com
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment