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>

# 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
# Set up HHVM
wget -O - | sudo apt-key add -
echo deb wheezy main | sudo tee /etc/apt/sources.list.d/hhvm.list

# update apt

# 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/
sudo /etc/init.d/nginx restart
sudo /etc/init.d/hhvm restart

mysql_install "$DB_PASSWORD" && mysql_tune 40

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


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

# download, extract, chown, and get our config file started
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 -o $VPATH/core.php
curl -o $VPATH/init.php
curl -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 = '';\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

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


# Set up pathogen
mkdir -p ~/.vim/autoload ~/.vim/bundle
curl -Sso ~/.vim/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