trog's WordPress with HHVM/Nginx [beta]

Supports: Debian 7 (64-bit); Ubuntu 12.04 LTS (64-bit)

Source Code

#!/bin/bash -x
# <UDF name="db_password" Label="MySQL root Password" />
 
source <ssinclude StackScriptID=1>

#
# BETA SOFTWARE. USE AT YOUR OWN RISK. 
#
# WARNING: this performs some actions that might be destructive on some systems! 
# It is intended for use when reinstalling a new operating system. 
#

# Install curl, used to retrieve some components
if [ ! -e /usr/bin/curl ]; then
		aptitude -y install curl
fi
 
# Set up HHVM
wget -O - http://dl.hhvm.com/conf/hhvm.gpg.key | sudo apt-key add -
echo deb http://dl.hhvm.com/debian wheezy main | sudo tee /etc/apt/sources.list.d/hhvm.list

# update apt
system_update

# Install Nginx - before HHVM 
sudo apt-get -y install nginx

# Add index.php to the Nginx config file and remove index.htm because, well, why not?
sed -i 's/index.html index.htm/index.html index.php/' /etc/nginx/sites-enabled/default


# Install HHVM
sudo apt-get -y install hhvm
sudo /usr/share/hhvm/install_fastcgi.sh
sudo /etc/init.d/nginx restart
sudo /etc/init.d/hhvm restart

postfix_install_loopback_only
mysql_install "$DB_PASSWORD" && mysql_tune 40

#
# Begin Install WordPress
#
if [ ! -e /usr/bin/wget ]; then
		aptitude -y install wget
fi

VPATH="/usr/share/nginx/www"

if [ ! -n "$VPATH" ]; then
	echo "Something horrible happened, can't Nginx document root!"
	return 1;
fi

# download, extract, chown, and get our config file started
cd $VPATH
wget http://wordpress.org/latest.tar.gz
tar xfz latest.tar.gz
mv wordpress/* $VPATH
rmdir wordpress/
mv index.html original_index.html
# Set up HipHop type checking in the WP project dir
echo > .hhconfig
chown -R www-data: wordpress/
cd $VPATH/wordpress
cp wp-config-sample.php wp-config.php
chown www-data wp-config.php
chmod 640 wp-config.php

##
# Start XHP setup
# Install the XHP header files
# FIXME: this could probably be a git pull. 

curl https://raw.githubusercontent.com/facebook/xhp/master/php-lib/core.php -o $VPATH/core.php
curl https://raw.githubusercontent.com/facebook/xhp/master/php-lib/init.php -o $VPATH/init.php
curl https://raw.githubusercontent.com/facebook/xhp/master/php-lib/html.php -o $VPATH/html.php

# Fix the XHP header files so they have the right header. At the time of writing (2014-07-04), the XHP core
# files in Github still use the PHP header. The HHVM at this time has XHP built in, but without this change 
# you'll get a Fatal that looks like the below in error logs:
# Fatal error: syntax error, unexpected ':' in /usr/share/nginx/www/core.php on line 18

sed -i 's/<?php/<?hh/' core.php
sed -i 's/<?php/<?hh/' init.php
sed -i 's/<?php/<?hh/' html.php

# Create a test XHP file. 
printf "<?hh\nrequire_once 'init.php';\n\$href = 'http://www.facebook.com';\necho <a href={\$href}>Facebook</a>;\n" > $VPATH/test_xhp.php

#
# End XHP setup
##

# Database configuration
WPPASS=$(randomString 20)
mysql_create_database "$DB_PASSWORD" wordpress
mysql_create_user "$DB_PASSWORD" wordpress "$WPPASS"
mysql_grant_user "$DB_PASSWORD" wordpress wordpress

# configuration file updates
for i in {1..8}
	do sed -i "0,/put your unique phrase here/s/put your unique phrase here/$(randomString 50)/" wp-config.php
done

sed -i 's/database_name_here/wordpress/' wp-config.php
sed -i 's/username_here/wordpress/' wp-config.php
sed -i "s/password_here/$WPPASS/" wp-config.php

#
# End Install WordPress
#

restartServices

# Set up pathogen
mkdir -p ~/.vim/autoload ~/.vim/bundle
curl -Sso ~/.vim/autoload/pathogen.vim https://raw.github.com/tpope/vim-pathogen/master/autoload/pathogen.vim

# Copy HHVM vim setup into vim config 
# FIXME: this might be destructive for the vim config, YMMV
ln -s /usr/share/hhvm/hack/vim ~/.vim/bundle/hack-vim

echo "execute pathogen#infect()" >> ~/.vimrc
echo "syntax on" >> ~/.vimrc
echo "filetype plugin indent on" >> ~/.vimrc

# FIXME this doesn't seem to work on Deb7
goodstuff