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

HHVM (Hip Hop Virtual Machine) is a just-in-time compiler developed by Facebook to run applications that are written in PHP and Hack language. HHVM is faster than the traditional PHP engine from ZEND and is used by Facebook to serve billions of web requests per day. HHVM has a 9x higher throughput of web requests and over a 5x reduction in memory consumption compared with the Zend PHP 5.2 engine + APC. see more here.

This tutorial describes the steps to install WordPress with Nginx, MariaDB and HHVM on Ubuntu 16.04 Server - 64bit.

Prerequisites

I assume you have installed on your machine:

  1. Ubuntu 16.04 Server with 64-bit architecture, because HHVM is running on 64-bit only.
  2. That you have root/ sudo access to the server.

So this is what we will do in this tutorial:

  • Install Nginx.
  • Install and Configure MariaDB.
  • Install and Configure HHVM
  • Install and Configure Wordpress

The installation commands have to be run as root user. Run:

sudo -s

to become the root user on your server.

Install Nginx

Nginx web server is available in the Ubuntu repository. You can install it with the apt command:

apt-get update
apt-get install nginx

Start Nginx when the installation finished.

systemctl start nginx

Now test with your browser, open the server IP: http://192.168.1.108/. Replace the IP in the URL with your own IP.

Nginx has been started

Install and Configure MariaDB

In this tutorial, I will install MariaDB as a replacement for MySQL to take advantage of its better performance. MariaDB is a fork of MySQL maintained by the original MySQL Developer Monty Widenius.

Install MariaDB with apt-get command:

apt-get install mariadb-client mariadb-server

Now you can start MariaDB (the MariaDB service is named mysql):

systemctl start mysql

When MariaDB is running, set MariaDB root password to secure the database:

mysql_secure_installation

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

The root password for MariaDB has been set and you can log in to MariaDB prompt with your password.

mysql -u root -p

TYPE YOUR PASSWORD

Now create a new database with the name wordpressdb and new user with the name wpuser for the WordPress installation. You can do that with the commands below. Please replace 'wpuser@' with a secure password that will be used ass access credentials for the new WordPress database.

create database wordpressdb;
create user [email protected] identified by 'wpuser@';
grant all privileges on wordpressdb.* to [email protected] identified by 'wpuser@';
flush privileges;
\q

Create the WordPress database and user.

Install and Configure HHVM

Add the HHVM repository to your Ubuntu repository file /etc/apt/sources.list and update the repository:

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-get update

Now let`s install HHVM:

apt-get install -y hhvm

When the installation is finished, configure  the Nginx web server to use HHVM:

/usr/share/hhvm/install_fastcgi.sh

To start HHVM automatically on system boot up, run this command:

update-rc.d hhvm defaults

and we will use HHVM for /usr/bin/php even if you have php-cli installed:

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

Now start HHVM:

systemctl start hhvm

Now it is time to test HHVM, I will test it in the browser and on the server console/terminal.

Create new file called info.php in the /var/www/html/ directory:

cd /var/www/html/
nano info.php

And add the PHP code below:

<?php
phpinfo();
?>

Now edit nginx virtualhost file /etc/nginx/sites-available/default with vim, and add index.php :

vim /etc/nginx/sites-available/default

Add new index.php:

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

Save and exit.

Nginx config file

Then access the file in your browser: http://192.168.1.108/info.php. If you can see the word HHVM in your web page, then HHVm is working correctly.

PHP info with HHVM

Finally, test HHVM in your server console/terminal, type this command:

php info.php
php -v

HHVM test on the shell

The first command shall show the word "HipHop", the second command the HHVM version.

Installing Wordpress

Download WordPress and extract it:

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

Wordpress has been extracted into the "wordpress" directory, you will have to move all WordPress files and directories to /var/www/html/, you can do this with the commands below:

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

Now change the owner for WordPress files to the user and group www-data, usually all files under /var/www/html/ directory are owned by www-data user and group. Run these commands to change the file and directory ownership:

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

Then rename the file wp-config-sample.php to wp-config.php, and edit the file to set the database name, database user and password that we created during the database setup.

mv wp-config-sample.php wp-config.php
nano wp-config.php

DB_NAME = wordpressdb
DB_USER = wpuser
DB_PASSWORD = wpuser@

Set the database details in the WordPress configuration file.

Then restart Nginx:

systemctl restart nginx

When Nginx is restarted, try to access server IP: http://192.168.1.108/, you will be redirected to the WordPress Installation.

Please choose your language, example: English(United States) and press the button Continue.

Select WordPress installation language

Now fill in the username, password that shall be used to authenticate the WordPress administrator and your email address and press the Install Wordpress button.

Set username and password for WordPress

Wait until the installation is finished, then login to the WordPress site: http://192.168.1.108/wp-login.php and input your username and password:

WordPress Login

Now you can see the WordPress Dashboard.

WordPress Dashboard

Or visit WordPress home page http://192.168.1.108/.

WordPress Homepage

Wordpress is installed with HHVM + Nginx web server in your Ubuntu 16.04 server.

Conclusion

HHVM is an open source project designed to execute programs written in Hack and PHP language that runs PHP applications faster and with less memory consumption than the traditional ZEND engine. The latest WordPress version runs fine on HHVM.

Share this page:

4 Comment(s)

Add comment

Comments

From: raqdevil at: 2016-11-26 21:49:52

How do i change from the ip to Domain name?

From: Stephen at: 2016-11-28 00:38:24

Go into wordpress and then set it up in the wordpress settings

From: andrew at: 2016-12-01 04:57:02

Why install HHVM? can you help me to understand it? Is install only nginx, mariadb are enough? Thanks

From: till at: 2016-12-01 07:26:17

HHVM is used to process / run the php files. It is used as a fast replacement for the "traditional" PHP.