Skip to content

Instantly share code, notes, and snippets.

@windyjonas
Created September 12, 2013 22:02
Show Gist options
  • Save windyjonas/6544461 to your computer and use it in GitHub Desktop.
Save windyjonas/6544461 to your computer and use it in GitHub Desktop.
###########################################
# Constants, set and forget
###########################################
# temp storage for the wordpress tarball
TMP_STORAGE=/home/USER/wptemp
# web root for the wordpress site
WWWROOT=/var/www
# Privileged db use/pwd for creating database and granting rights
DBROOT=root
DBROOTPWD=XXXX
# Database owner/pwd for the WordPress tables
DBUSER=dbusername
DBPWD=XXXX
# user:group for the web server
WWWUSER=nginx
WWWGRP=nginx
# network device used for detecting external ip address
DEVICE=eth0
###########################################
# ok, no touching down there
if [ ! -d "$TMP_STORAGE" ]; then
echo "$TMP_STORAGE doesn't exist"
exit 1
fi
# Get the WordPress stuff, the nightly build, unzip it
cd $TMP_STORAGE
wget http://wordpress.org/nightly-builds/wordpress-latest.zip
unzip wordpress-latest.zip
# Get the site name
echo -n "Domain name? : "
read -e WP_DIR
# mv the WordPress files to their final destination.
# we will add web server config later
cp -R wordpress ${WWWROOT}/${WP_DIR}
rm -rf wordpress*
# Create virtual host config for nginx.
# Use the template below and then replace the site name
ngx_template=$(cat <<NGXEOT
server { \n
listen 80; \n
server_name www.[DOMAIN]; \n
error_log /var/log/nginx/[DOMAIN].error.log crit; \n
\n
rewrite ^(.*)$ http://[DOMAIN]$1 permanent; \n
} \n
\n
server { \n
listen 80; \n
access_log /var/log/nginx/[DOMAIN].access.log gzip; \n
server_name [DOMAIN]; \n
error_log /var/log/nginx/[DOMAIN].error.log crit; \n
\n
root /var/www/[DOMAIN]/; \n
\n
include wp.conf; \n
} \n
NGXEOT
)
echo -e ${ngx_template//\[DOMAIN\]/$WP_DIR} > /etc/nginx/sites-available/${WP_DIR}.conf
ln -s /etc/nginx/sites-available/${WP_DIR}.conf /etc/nginx/sites-enabled/
# Create mysql database
dbname=${WP_DIR//[\.-]/_}
mysql -u ${DBROOT} -p${DBROOTPWD} <<QI
create database ${dbname}
QI
# Grant database to non-root user
mysql -u ${DBROOT} -p${DBROOTPWD} <<QI
grant all on ${dbname}.* to '${DBUSER}'@'localhost';
QI
# Mod the Wordpress config file so that the db config fits
sed -e "s/database_name_here/$dbname/"\
-e "s/username_here/${DBUSER}/"\
-e "s/password_here/${DBPWD}/" \
${WWWROOT}/${WP_DIR}/wp-config-sample.php \
> ${WWWROOT}/${WP_DIR}/wp-config.php
chown ${WWWUSER}:${WWWGRP} ${WWWROOT}/${WP_DIR}/wp-config.php
rm ${WWWROOT}/${WP_DIR}/wp-config-sample.php
# Reload web server
/etc/init.d/nginx reload
echo "Done!"
echo "Add this to your hosts file:"
echo ` ifconfig ${DEVICE} | grep inet | grep -v inet6 | cut -d ":" -f 2 | cut -d " " -f 1` ${WP_DIR}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment