Skip to content

Instantly share code, notes, and snippets.

@hanigamal
Created August 14, 2013 02:15
Show Gist options
  • Save hanigamal/6227483 to your computer and use it in GitHub Desktop.
Save hanigamal/6227483 to your computer and use it in GitHub Desktop.
WordPress Commandline Local Install
#!/bin/bash
#
# WP Commandline Local Install, by Brian Richards (@rzen)
#
# Creates a new directory, downloads WordPress, creates a database, sets up wp-config,
# optionally empties wp-content, and deletes other misc files. This compliments my local
# dev setup, outlined here: http://rzen.net/development/local-develoment-in-osx/
#
# Credit:
# Based on WPBuildr (https://github.com/AaronHolbrook/wpbuildr/). Props to Aaron Holbrook
# (@aaronjholbrook) and Brad Parbs (@bradparbs) for the awesome head-start!
#
# Usage:
# Save this file to /usr/bin/wp, then in terminal type "wp" to run (or ". wp" to run and exit
# to the resulting /wp-content/ folder). You can also specify both arguments on command line
# (e.g. "wp test1 y" will create a new dir named "test1" with an empty wp-content folder).
clear
echo '
`-/+osssssssssssso+/-`
./oys syo/.
.+ys: ..:/osyyhhhhyyso/:.. +sy+.
/ys: .+ydmmmmmmmmmmmmmmmmmmmdy+. :sy/
/h+` -odmmmmmmmmmmmmmmmmmmmmmmmmmmdo- `+h/
:ho` /hmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmds/ `oh:
`sy. /hmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm+ .ys`
.ho /mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmy oh.
.h+ `mmmmmmmm` `mmmmmmmh +h.
`ho ` /mmmmmmmmmmo .dmmmmmmmms ~~ oh`
oy .h` ymmmmmmmmmm: /mmmmmmmmmy` -d. yo
.d- ymy `dmmmmmmmmmd. ymmmmmmmmmh` /my -d.
oy -mmm+ /mmmmmmmmmmy .dmmmmmmmmmy ymm- yo
h+ +mmmd- smmmmmmmmmm+ /mmmmmmmmmm- :mmm+ +h
d/ smmmmh` `dmmmmmmmmmd` smmmmmmmmm: `dmmms /d
d/ smmmmms :mmmmmmmmm+ `dmmmmmmmd. smmmms /d
h+ +mmmmmm/ smmmmmmmh + /mmmmmmmy /mmmmm+ +h
oy -mmmmmmd. `dmmmmmd- +m/ smmmmmd. .dmmmmm- yo
.d- ymmmmmmh :mmmmm+ .dmd- `dmmmm/ ymmmmmy -d.
oy .dmmmmmmo smmmh hmmmh` :mmmy +mmmmmd. yo
`ho -dmmmmmd: `dmd+ .mmmmms smd- .dmmmmd- oh`
.h+ -dmmmmmd` :m+ dmmmmmm: `do hmmmmd- +h.
.ho .ymmmmmy + hmmmmmmmd. :` ommmmy. oh.
`sy. /hmmmm+ ommmmmmmmmy -dmmh/ .ys`
:ho /hmmd- :mmmmmmmmmmmo `hmh/ oh:
/h+ -odh` `dmmmmmmmmmmmd: oo- +h/
/ys: ~~ smmmmmmmmmmmmmd` :sy/
.+ys `/osyyhhhhyyso/:` ./sy+.
./oys+ +syo/.
`-/+osssssssssssso+/-`
'
# Title the project
# Use the title for:
# Directory name & DB Name
if [ ! $1 ]; then
read -p "Give your project a name (no hyphens allowed): " project
else
project=$1
fi
# Empty the wp-content directory?
if [ ! $2 ]; then
read -p "Empty the wp-content directory? (y/n): " delete_content
fi
mkdir $project
cd $project
echo ''
echo '-------------------------------------------------------------------------------'
echo ' DOWNLOADING WORDPRESS '
echo '-------------------------------------------------------------------------------'
echo ''
# download wordpress, extract and delete original tar and misc files
curl -H "Accept-Encoding: gzip,deflate" http://wordpress.org/latest.tar.gz > latest.tar.gz
tar --strip-components=1 -zxf latest.tar.gz
rm latest.tar.gz
rm license.txt
rm readme.html
rm wp-config-sample.php
echo ''
echo '-------------------------------------------------------------------------------'
echo ''
echo "Created directory \"$project\""
echo "Downloaded WordPress and deleted unneeded files."
# Maybe delete all contents of wp-content
if [ 'y' == $delete_content ]; then
rm -rf wp-content/*
echo 'Emptied /wp-content/'
fi
# Setup our wp-config file
echo "<?php
/**
* The base configurations of the WordPress.
*
* This file has the following configurations: MySQL settings, Table Prefix,
* Secret Keys, WordPress Language, and ABSPATH. You can find more information
* by visiting {@link http://codex.wordpress.org/Editing_wp-config.php Editing
* wp-config.php} Codex page. You can get the MySQL settings from your web host.
*
* This file is used by the wp-config.php creation script during the
* installation. You don't have to use the web site, you can just copy this file
* to "wp-config.php" and fill in the values.
*
* @package WordPress
*/
// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', '$project');
/** MySQL database username */
define('DB_USER', 'root');
/** MySQL database password */
define('DB_PASSWORD', '');
/** MySQL hostname */
define('DB_HOST', 'localhost');
/** Database Charset to use in creating database tables. */
define('DB_CHARSET', 'utf8');
/** The Database Collate type. Don't change this if in doubt. */
define('DB_COLLATE', '');
/**
* WordPress Database Table prefix.
*
* You can have multiple installations in one database if you give each a unique
* prefix. Only numbers, letters, and underscores please!
*/
\$table_prefix = 'wp_';
/**#@+
* Authentication Unique Keys and Salts.
*
* Change these to different unique phrases!
* You can generate these using the {@link https://api.wordpress.org/secret-key/1.1/salt/ WordPress.org secret-key service}
* You can change these at any point in time to invalidate all existing cookies. This will force all users to have to log in again.
*
* @since 2.6.0
*/
" > wp-config.php
curl -s https://api.wordpress.org/secret-key/1.1/salt/ >> wp-config.php;
echo "
/**
* WordPress Localized Language, defaults to English.
*
* Change this to localize WordPress. A corresponding MO file for the chosen
* language must be installed to wp-content/languages. For example, install
* de_DE.mo to wp-content/languages and set WPLANG to 'de_DE' to enable German
* language support.
*/
define('WPLANG', '');
/**
* For developers: WordPress debugging mode.
*
* Change this to true to enable the display of notices during development.
* It is strongly recommended that plugin and theme developers use WP_DEBUG
* in their development environments.
*/
define('WP_DEBUG', true);
define('FS_METHOD', 'direct');
/* That's all, stop editing! Happy blogging. */
/** Absolute path to the WordPress directory. */
if ( !defined('ABSPATH') )
define('ABSPATH', dirname(__FILE__) . '/');
/** Sets up WordPress vars and included files. */
require_once(ABSPATH . 'wp-settings.php');" >> wp-config.php
echo 'Created /wp-config.php'
# create local database
mysql -u root -e "CREATE DATABASE $project"
echo "Created database \"$project\"."
echo 'Install complete!'
cd wp-content
pwd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment