How to install WordPress with Nginx, HHVM and MariaDB on Ubuntu 16.04

Wordpress with Nginx, HHVM and MariaDB

Introduction

If you’ve never heard about HHVM, it’s an open-source Virtual Machine designed for executing programs written in Hack and PHP. For performance reasons, it uses a just-in-time compilation process.
Just like other similar projects, HHVM performs execution in a two-phase approach: first, it compiles PHP and Hack in an intermediate bytecode, then this bytecode is translated into AMD64 machine code at runtime, with a JIT (just-in-time) compiler.
This tutorial demonstrates how to install WordPress with MariaDB, Nginx and, of course, HHVM on Ubuntu 16.04.

Prerequisites

As stated on the official page, HHVM supports only 64 bit architectures, so you need Ubuntu 16.04 Server 64bit.

Install Nginx

First, we install Nginx, which is available in Ubuntu repositories. Execute the following command:

# apt install nginx

The installation process is very quick. When it is complete, start Nginx:

# systemctl start nginx

Install and configure MariaDB

MariaDB is also available in the repository, so just use apt:

# apt-get install mariadb-client mariadb-server

MariaDB is a MySQL fork, and it uses its name for the systemd service:

# systemctl start mysql

Set MariaDB root password to secure your database:

# mysql_secure_installation

You will be asked for the following configuration parameters:

Enter current password for root (enter for none): PRESS ENTER

Set root password? [Y/n] Y
ENTER YOUR PASSWORD

Remove anonymous users? [Y/n] Y
Disallow root login remotely? [Y/n] Y
Remove test database and access to it? [Y/n] Y
Reload privilege tables now? [Y/n] Y

Once that step is complete you can access the MariaDB database with your password:

$ mysql -u root -p

Use the MariaDB prompt to create a new database for WordPress. In this tutorial, we use mywordpressdb as the database name, and wordpressuser as the username for the WP installation. So our code looks like this:

	mysql> CREATE DATABASE mywordpressdb;
	mysql> CREATE USER wordpressuser@localhost IDENTIFIED BY 'my_strong_password';
	mysql> GRANT ALL PRIVILEGES ON mywordpressdb.* to wordpressuser@localhost IDENTIFIED BY 'my_strong_password';

Next, you can flush privileges and exit:

	mysql> FLUSH PRIVILEGES;
	mysql> EXIT;

Install HHVM

HHVM is not available in the Ubuntu repository, so, first, it’s necessary to add an external one. This requires editing

/etc/apt/sources.list

and updating repos. Just execute the following commands:

	$ wget -O - http://dl.hhvm.com/conf/hhvm.gpg.key | sudo apt-key add -
	$ echo deb http://dl.hhvm.com/ubuntu xenial main | sudo tee /etc/apt/sources.list.d/hhvm.list
	# apt update

Now, install HHVM with apt:

# apt install -y hhvm

Configure and test HHVM

After installation, in

/usr/share/hhvm

there is a script for configuring the Nginx web server to use HHVM. Just execute the following:

# /usr/share/hhvm/install_fastcgi.sh

This is a quick process, at the end of which you can start HHVM:

# systemctl start hhvm.service

If you need to run web scripts, and you want it to start at boot, execute the command:

# update-rc.d hhvm defaults

You can decide to use HHVM for

/usr/bin/php

even if you have a php-cli already installed:

# /usr/bin/update-alternatives --install /usr/bin/php php /usr/bin/hhvm 60

Next, you can test HHVM in different ways (for example, you can call it on existing PHP scripts present in your filesystem, just like php-cli). In this case, we use it on the web server. So, create a file called

info.php

in

/var/www/html

and enter the following lines:

<?php
phpinfo();
?>

Edit Nginx Virtual Host file, adding in it index.php:

	# $EDITOR /etc/nginx/sites-available/default

Here:

index index.php index.html index.htm index.nginx-debian.html;

After saving, exit, and test. With your browser, go to

http://localhost/info.php

Here, you should see HHVM on top of the page: this means that it is working as expected.

Install WordPress

Now, you must install WordPress. This is quite easy, just execute the commands:

	# cd /var/www/html
	# wget wordpress.org/latest.zip
	# unzip latest.zip

The

unzip

command will create a new folder,

wordpress

. Move all of its content into 

/var/www/html
	# mv wordpress/* .
	# rm -rf wordpress/

Change the owner for the WordPress files:

	# find . -type d -exec chown www-data:www-data {} \;
	# find . -type f -exec chown www-data:www-data {} \;

Rename

wp-config-sample.php

to

wp-config.php

, then edit it:

	# mv wp-config-sample.php wp-config.php
	# $EDITOR wp-config.php

Here, change database informations using the one you specified in the MariaDB configuration process:

	DB_NAME = mywordpressdb
	DB_USER = wordpressuser
	DB_PASSWORD = my_strong_password

Restart the server:

	# systemctl restart nginx

After that, go to your server IP, and you will be redirected to the WordPress installation, which is totally created in your web browser.

After filling out all of the required forms, WordPress will be ready for you! And that’s all you need for creating you website with WP on an Ubuntu 16.04 running Nginx, with HHVM.