Installing WordPress with HHVM, Nginx and MariaDB on Ubuntu 12.04

HHVM is an open source virtual machine designed to run programs written in PHP. HHVM stands for HipHop Virtual Machine, and was originally developed by Facebook to improve application performance, and for those who don’t know MariaDB it’s in place of MySQL. In this tutorial, we will show you step by step how to install WordPress with HHVM, Nginx, and MariaDB on Ubuntu 12.04 LTS.

Update the system and install the required packages.

apt-get update && apt-get upgrade
apt-get install python-software-properties curl

Install MariaDB and create a database.

apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xcbcb082a1bb943db
add-apt-repository 'deb http://ftp.osuosl.org/pub/mariadb/repo/5.5/ubuntu precise main'
apt-get update
echo -e "Package: *nPin: origin ftp.osuosl.orgnPin-Priority: 1000" | tee /etc/apt/preferences.d/mariadb
apt-get install mariadb-server

mysql -uroot -p
MariaDB [(none)]> CREATE DATABASE my_db;
MariaDB [(none)]> GRANT ALL PRIVILEGES ON my_db.* TO 'my_user'@'localhost' IDENTIFIED BY 'my_user_passwd';
MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> q

Install and configure Nginx 1.4.x

add-apt-repository ppa:nginx/stable
apt-get install nginx

Set worker_processes to the number of processors on the system.

To find out the number of processors in the system and set worker_processes, run the following command:

sed -i "0,/^worker_processes/ s/^worker_processes .*$/worker_processes `grep -c processor /proc/cpuinfo`;/"  /etc/nginx/nginx.conf

Install hhvm and hhvm-FastCGI

apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 5A16E7281BE7A449
echo deb http://dl.hhvm.com/ubuntu precise main | tee /etc/apt/sources.list.d/hhvm.list
apt-get update
apt-get install hhvm-fastcgi

If you want to use PHP from the command line, then you will need to create PHP symlinks for HHVM

ln -s $(which hhvm) /usr/local/bin/php

# php -v
HipHop VM v2.3.3 (rel)
Compiler: tags/HHVM-2.3.3-0-g4cf537888ba4ae253cc3dd0b04fe2c5bca5d24e4
Repo schema: 19f7626936db8612e50b3393be6e2cb7547771c8

Create the root directory of your website, download and extract WordPress

mkdir -p /var/www/yourwebsite.ru/{public_html,logs}
wget -q -O - http://wordpress.org/latest.tar.gz | tar -xzf - --strip 1 -C /var/www/yourwebsite.ru/public_html
chown www-data: -R /var/www/yourwebsite.ru/public_html

To install WordPress use our article on installing WordPress.

Create a new nginx server block

# cat <<'EOF' > /etc/nginx/sites-available/yourwebsite.ru
server {
  server_name yourwebsite.ru;
  listen 80;
  root /var/www/yourwebsite.ru/public_html;
  access_log /var/www/yourwebsite.ru/logs/access.log;
  error_log /var/www/yourwebsite.ru/logs/error.log;
  index index.php;

  location / {
    try_files $uri $uri/ /index.php?q=$uri&$args;
  }

  location ~* .(jpg|jpeg|gif|css|png|js|ico|html)$ {
    access_log off;
    expires max;
  }

  location ~ /.ht {
    deny  all;
  }

  location ~ .php$ {
    fastcgi_index index.php;
    fastcgi_keep_conn on;
    include /etc/nginx/fastcgi_params;
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  }
}
EOF

ln -s /etc/nginx/sites-available/yourwebsite.ru /etc/nginx/sites-enabled/yourwebsite.ru
/etc/init.d/nginx restart

Set all services to start at boot

update-rc.d nginx defaults
update-rc.d hhvm-fastcgi defaults
update-rc.d mysql defaults

Finally, open your browser, enter your website address and follow the onscreen instructions.

Sidebar