How to Install WordPress with Nginx, MariaDB and HHVM Support on Ubuntu

Share

WordPress supports a variety of open-source tools and applications. For example, you can run WordPress with the support of the LAMP or LEMP stack.

This brief tutorial is going to show students and new users an easy way to install and run WordPress with the support of HHVM ( Hip Hop Virtual Machine). HHVM was developed by Facebook to run applications that are based on PHP and the Hack language.

Most will agree that HHVM is faster than the traditional PHP stack. So, if you want to improve WordPress’ performance, running it on HHVM, MariaDB and Nginx might help a bit.

To get the setup correctly, follow the steps below:

Prepare Ubuntu Server

Before installing packages on Ubuntu systems, you must first update and prepare the machine. Run the commands below to update and remove absolute packages from Ubuntu

sudo apt-get update && sudo apt-get dist-upgrade && sudo apt-get autoremove

After running the command above, you may want to reboot depending on what was installed and upgraded.

Installing the Nginx web server

Now that the Ubuntu machine is updated, run the commands below to install Nginx.

sudo apt-get install nginx

After installing Nginx, the commands below can be used to stop, start and enable Nginx

sudo systemctl stop nginx.service
sudo systemctl start nginx.service
sudo systemctl enable nginx.service

Install MariaDB

After installing the Nginx web server, the next step will be to install the MariaDB database server. To do that, run the commands below.

sudo apt-get install mariadb-server mariadb-client

After installing MariaDB, the commands below can be used to manage the database server

sudo systemctl stop mysql.service
sudo systemctl start mysql.service
sudo systemctl enable mysql.service

When you’re done running the commands above, run the command below to secure MariaDB and create the root password

sudo mysql_secure_installation

When prompted, use the guide below to answer the questions

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

Set root password? [Y/n] Y
CREATE 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

Create WordPress Database

The next step in the process is to create a database and database user for WordPress. To do that, we’re going to create a WordPress database called wpdb and a user called wpuser.

To do that, run the command below to logon into the MariaDB server

sudo mysql -u root -p

Then run the commands below to create a database called wpdb

CREATE DATABASE wpdb;

Next, run the commands below to create a database user called wpuser

CREATE USER wpuser;

Grant all privileges to the user to manage wpdb

GRANT ALL PRIVILEGES ON wpdb.* to 'wpuser'@'localhost' IDENTIFIED BY 'new_password_here';

Finally, flush the permission to save your changes

FLUSH PRIVILEGES;
exit

Installing HHVM

To install HHVM on Ubuntu you must add its repository and key. To do that, run the commands below to install the repository’s key.

wget -O - http://dl.hhvm.com/conf/hhvm.gpg.key | sudo apt-key add -

Run the commands below to install the repository

sudo sh -c "echo 'deb http://dl.hhvm.com/ubuntu '$(lsb_release -cs)' main' > /etc/apt/sources.list.d/HHVM.list"

After that, run the commands below to install HHVM

sudo apt-get update
sudo apt-get install -y hhvm

Nginx, run the commands below to configure HHVM to work with the Nginx web server

/usr/share/hhvm/install_fastcgi.sh

Run the commands below to make HHVM the default PHP compiler

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

Finally, fun the commands below to start and enable HHVM

sudo systemctl start hhvn
sudo update-rc.d hhvm defaults

Configure Nginx and Install WordPress

Now that all the servers and modules are installed, go and configure Nginx to serve PHP applications. To do that, open the Nginx default site configuration and add an index for PHP.

sudo nano /etc/nginx/sites-available/default

Then add the PHP index.

 # Add index.php to the list if you are using PHP
  index index.php index.html index.htm index.nginx-debian.html;

Save the file and you’re done.

Download files

Now that you’ve installed all the servers and packages that WordPress needs, it’s time to download WordPress content. To download the content, run the commands below.

cd /tmp/ && wget http://wordpress.org/latest.tar.gz

Next, extract the downloaded content by running the commands below.

tar -xvzf latest.tar.gz

Configure WordPress Site

After extracting WordPress content, the first thing you’ll want to do is delete the Apache default file in its root directory.

sudo rm /var/www/html/index.nginx-debian.html

Next, move WordPress content to Apache2’s root directory by running the commands below.

sudo mv wordpress/* /var/www/html/

After moving WordPress content to its root directory, use the command below to make a copy of wp-config-sample.php file and name it wp-config.php.

The wp-config.php is the default configuration file for WordPress in its root folder.

sudo cp /var/www/html/wp-config-sample.php /var/www/html/wp-config.php

Next, edit wp-config.php file and make the below changes.

sudo nano /var/www/html/wp-config.php

// ** MySQL settings – You can get this info from your web host ** //
/** The name of the database for WordPress */
define(‘DB_NAME’, ‘wpdb‘);

/** MySQL database username */
define(‘DB_USER’, ‘wpuser‘);

/** MySQL database password */
define(‘DB_PASSWORD’, ‘new_password_here‘);

Save your changes when done.

Finally, run the commands below to set the correct files and folder permissions for WordPress to function properly.

sudo chown -R www-data:www-data /var/www/html
sudo chmod -R 755 /var/www/html/

After all of the above, restart the Apache2 web server.

sudo systemctl restart nginx.service

Start installation

The final step is to open your web browser and browse to the server IP address or hostname. You should be prompted with the WordPress default setup page.

http://localhost

If you see this page, then everything went perfectly!

WordPress default setup page

Continue with the WordPress setup wizard until you’re done. When you’re done. you’ll have fully installed WordPress on HHVM.

Enjoy!