Install and run Magento on HHVM and Nginx - PPC64/hhvm GitHub Wiki

Install and run Magento on HHVM and Nginx

Introduction

Magento is an open source e-commerce software and content management system for e-commerce websites based on the PHP Zend Framework. It uses MySQL or MariaDB as database backend. This install guide shows how to install Magento 2 with Nginx, and MariaDB as the database. This guide uses Ubuntu 16.04 (Xenial Xerus) as server operating system on POWER8 (ppc64el).

Prerequisites

First log as sudo and then update packages:

sudo su
apt-get update

Check if you have curl and php installed on machine before:

curl -v
php -v

If you don't have curl or php installed need to install those programs before proceed

apt-get install curl php -y

##Step 1 - Install Nginx

apt-get install nginx -y

Verify that nginx has been installed properly by checking the port:

netstat -plntu | grep 80

##Step 2 - Install MariaDB

apt-get install mariadb-server mariadb-client -y

Set MariaDB user/password:

mysqladmin -u root password mypassword

Enter the password when prompted:

Mysql password prompt

Then connect to the MariaDB shell (with command mysql) with your root password, create a database with the name magentodb and a user magentouser with the password magentouser@.

Login to the MariaDB shell:

mysql -u root -p

On MariaDB shell run the following command:

CREATE DATABASE magentodb;
CREATE USER magentouser@localhost IDENTIFIED BY 'magentouser@';
GRANT ALL PRIVILEGES ON magentodb.* TO magentouser@localhost IDENTIFIED BY 'magentouser@';
FLUSH PRIVILEGES;
\q

MariaDB magento2 database and user configuration

Database was created and configured.


ATTENTION

If you got a Access denied for user 'root'@'localhost error when try to access MariaDB you can try to reset root password:

sudo mysql -u root
use mysql;
update user set plugin='' where User='root';
flush privileges;
exit;

##Step 3 - Install Magento 2

###Install PHP Composer

Go to a /tmp directory, download the composer installer file with curl and run it to install composer:

cd /tmp
curl -sS https://getcomposer.org/installer | php

Move the file composer.phar file to the bin directory of your server and rename it to composer so it can be executed easily:

mv composer.phar /usr/bin/composer

Verify that composer is working:

composer -v

###Download and extract Magento2

Go to the web directory /var/www/ and download Magento from Github, then unpack:

 cd /var/www/
 wget https://github.com/magento/magento2/archive/2.0.7.tar.gz
 tar -xzvf 2.0.7.tar.gz
 mv magento2-2.0.7/ magento2/

Now you have to configure a Magento Key. This account is required to use Magento and the Magento composer store. First you need to create the account at Magento site by click in Register button:

Figure 3 - Creating a login at Magento

After fill the fields and agree with terms you have to access the account and set a pair of Secure Keys. Just type your user name and generate the pair of keys it will be required when installing Magento:

Figure 4 - Create a pair of Secure Keys

Now you can install Magento. Go to directory /var/www/magento2 and run:

cd /var/www/magento2/
composer install -v

You will be asked for the Magento authentication, use the public key as username and the private key for the password:

Figure 5 - Magento authentication

Step 4 - Install HHVM

Now you can install HHVM. The easiest way to do that is via apt-get. First you have to add the PPA which contains hhvm-3.15-ppc64el package:

sudo add-apt-repository ppa:ibmpackages/hhvm
sudo apt-get update

And then:

sudo apt-get install hhvm

If you want to install HHVM from source please refer to the section Install HHVM on Ubuntu 16.04 on this wiki.

Setup HHVM to work with fastcgi

Open /etc/hhvm/server.ini file and edit this file to look's like bellow:

; php options

pid = /var/run/hhvm/pid

; hhvm specific 

hhvm.server.port = 9000
hhvm.server.type = fastcgi
hhvm.server.default_document = index.php
hhvm.log.use_log_file = true
hhvm.log.file = /var/log/hhvm/error.log
hhvm.repo.central.path = /var/run/hhvm/hhvm.hhbc

This will run HHVM server at port 9000 using fastcgi

Step 5 - Configure Nginx

Now lets check if hhvm and nginx properly work together. Copy the following content to the file /etc/nginx/sites-avaliable/default:

server {
        listen 80 default_server;
        listen [::]:80 default_server;

        root /var/www/html;

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

        access_log /var/log/nginx/access.log;

        server_name _;
        location ~ \.(hh|php)$ {
           fastcgi_keep_conn on;
           fastcgi_pass   127.0.0.1:9000;
           fastcgi_index  index.php;
           fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
           include        fastcgi_params;
        }

        location / {
                try_files $uri $uri/ =404;
        }             
}

This will create a virtual host at nginx and set location to a fastcgi server located at 127.0.0.1 (localhost) using port 9000.

Now create a test.php file in /var/www/html:

 cd /var/www/html
 cat > test.php
 <php?
     if (defined('HHVM_VERSION')) {
       echo "HHVM OK";
     }

Now you need to restart nginx and hhvm:

 systemctl restart nginx
 systemctl restart hhvm

Now you can access test.php from our server by typing localhost/test.php at your browser or run:

curl localhost/test.php 

This should print OK on terminal.

###Set Magento Virtual Host

Magento offers a ready-made Nginx virtual host configuration, so we just have to include it in our configuration. Replace contents of /etc/nginx/sites-avaliable/default with:

upstream fastcgi_backend {
  server 127.0.0.1:9000;
}
server {
        listen 80 default_server;
        listen [::]:80 default_server;

        access_log /var/log/nginx/access.log;

        server_name _;

        set $MAGE_ROOT /var/www/magento2;
        set $MAGE_MODE developer;

        include /var/www/magento2/nginx.conf.sample;

        location ~ /\.ht {
            deny all;
        }
}

And then restart nginx and hhvm again:

 systemctl restart nginx
 systemctl restart hhvm

Now Magento2 is installed and running on HHVM. You can access Magento by access localhost using a browser.