├── README.md
└── wp.sh
/README.md:
--------------------------------------------------------------------------------
1 | New MAMP WordPress Install via Shell
2 | =================
3 |
4 | Roll a new WordPress installation for MAMP with this quick shell script (allows custom inputs for directory, database name, and WP version).
5 |
6 | Assuming you have MAMP installed in `/Applications/MAMP/htdocs`:
7 |
8 | 1. Download the shell script.
9 | 1. Run it in Terminal.
10 | 1. Answer the prompts.
11 |
12 | From my brief write-up:
13 |
14 | > I decided to combine the most common, repetitive steps of the process into one useful shell script that:
15 |
16 | > 1. Creates a new directory (and lets me name it)
17 | > 1. Downloads WordPress from GitHub and checks out whatever version I tell it to
18 | > 1. Creates a new database (and lets me name it) and gives the MySQL user proper permissions
19 | > 1. Generates my security keys and adds them to `wp-config.php`
20 | > 1. Adds my database name, username, and password to `wp-config.php`
21 | > 1. Opens up `wp-admin/install.php` to lets me complete installation
22 |
23 | FAQ
24 | -----------------
25 |
26 | Getting _fatal: could not create work tree dir..._ or having other permissions-related issues? Put `sudo` in front of the path to the script before running it.
27 |
--------------------------------------------------------------------------------
/wp.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | cd /Applications/MAMP/htdocs
3 | printf "What would you like to name your new WordPress root directory (i.e. mywpdir)? "
4 | read NEWDIR
5 | git clone https://github.com/WordPress/WordPress.git $NEWDIR
6 | cd $NEWDIR
7 | printf "What version of WordPress would you like to use? It must be a non-beta release (i.e. 3.4.2). "
8 | read WPVER
9 | git checkout $WPVER
10 | rm -rf .git
11 | printf "MySQL User: "
12 | read MYSQLUSER
13 | if [ "$MYSQLUSER" = "" ]; then
14 | set MYSQLUSER = "root"
15 | fi
16 | printf "MySQL Password: "
17 | read MYSQLPWD
18 | printf "What would you like to name your new database (i.e. newwpdb)? "
19 | read NEWDB
20 | echo "CREATE DATABASE $NEWDB; GRANT ALL ON $NEWDB.* TO '$MYSQLUSER'@'localhost';" | ../../Library/bin/mysql -u$MYSQLUSER -p$MYSQLPWD
21 |
22 | if [ -f ./wp-config.php ]
23 | then
24 | open http://localhost:8888/$NEWDIR/wp-admin/install.php
25 | else
26 | cp -n ./wp-config-sample.php ./wp-config.php
27 | SECRETKEYS=$(curl -L https://api.wordpress.org/secret-key/1.1/salt/)
28 | EXISTINGKEYS='put your unique phrase here'
29 | printf '%s\n' "g/$EXISTINGKEYS/d" a "$SECRETKEYS" . w | ed -s wp-config.php
30 | DBUSER=$"username_here"
31 | DBPASS=$"password_here"
32 | DBNAME=$"database_name_here"
33 | sed -i '' -e "s/${DBUSER}/${MYSQLUSER}/g" wp-config.php
34 | sed -i '' -e "s/${DBPASS}/${MYSQLPWD}/g" wp-config.php
35 | sed -i '' -e "s/${DBNAME}/${NEWDB}/g" wp-config.php
36 | open http://localhost:8888/$NEWDIR/wp-admin/install.php
37 | fi
--------------------------------------------------------------------------------