Friday, November 14, 2014

Magento on HHVM 3.3 Nginx 1.6 on Ubuntu 14.04 trusty

No more Varnish! Love HHVM!

1.First this VPS box running Ubuntu 14.04 trusty 64 bit with 2 GB Memory and 2 Core CPU.
Please follow HHVM, Nginx and MariaDB 's offical installation guide to install:





After installation I have these files under /etc/apt/sources.list.d/:
nginx.list
deb http://nginx.org/packages/ubuntu/ trusty nginx


mariadb.list
deb http://mariadb.mirror.iweb.com//repo/10.0/ubuntu trusty main


hhvm.list
deb http://dl.hhvm.com/ubuntu trusty main


At this moment I have the version:

root@mds-magento:/var/www/magento/includes# dpkg -l|grep hhvm
ii hhvm 3.3.0~trusty amd64 HHVM virtual machine, runtime, and JIT for the PHP language
root@mds-magento:/var/www/magento/includes# dpkg -l|grep nginx
ii nginx 1.6.2-1~trusty amd64 high performance web server
root@mds-magento:/etc/apt/sources.list.d# dpkg -l|grep mariadb
ii libmariadbclient18 10.0.14+maria-1~trusty amd64 MariaDB database client library
ii mariadb-client-10.0 10.0.14+maria-1~trusty amd64 MariaDB database client binaries
ii mariadb-client-core-10.0 10.0.14+maria-1~trusty amd64 MariaDB database core client binaries
ii mariadb-common 10.0.14+maria-1~trusty all MariaDB database common files (e.g. /etc/mysql/conf.d/mariadb.cnf)
ii mariadb-server 10.0.14+maria-1~trusty all MariaDB database server (metapackage depending on the latest version)
ii mariadb-server-10.0 10.0.14+maria-1~trusty amd64 MariaDB database server binaries
ii mariadb-server-core-10.0 10.0.14+maria-1~trusty amd64 MariaDB database core server files


2.Share my Nginx config file:
/etc/nginx/nginx.conf


user www-data;
worker_processes 2;

error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;


events {
worker_connections 1024;
}


http {
include /etc/nginx/mime.types;
default_type application/octet-stream;

log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

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

sendfile on;
autoindex off;
#tcp_nopush on;

map $scheme $fastcgi_https { ## Detect when HTTPS is used
default off;
https on;
}

keepalive_timeout 10;

gzip on;
gzip_comp_level 2;
gzip_proxied any;
gzip_types text/plain text/css application/x-javascript application/xml application/xml+rss text/javascript;

include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}


/etc/nginx/hhvm.conf

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;
}


/etc/nginx/fastcgi_params


fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;

fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param HTTPS $https if_not_empty;

fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;

fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;

# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param REDIRECT_STATUS 200;


/etc/nginx/sites-enabled/magento

server {
listen 80;
server_name localhost;
rewrite / $scheme://www.$host$request_uri permanent; ## Forcibly prepend a www
}

server {
listen 80 default;

#charset koi8-r;
#access_log /var/log/nginx/log/host.access.log main;

root /var/www/magento;

location / {
index index index.html index.htm index.php;
try_files $uri $uri/ @handler;
}

## These locations would be hidden by .htaccess normally
location ^~ /app/ { deny all; }
location ^~ /includes/ { deny all; }
location ^~ /lib/ { deny all; }
location ^~ /media/downloadable/ { deny all; }
location ^~ /pkginfo/ { deny all; }
location ^~ /report/config.xml { deny all; }
location ^~ /var/ { deny all; }

location /. { ## Disable .htaccess and other hidden files
return 404;
}

location @handler { ## Magento uses a common front handler
rewrite / /index.php;
}

location ~ .php/ { ## Forward paths like /js/index.php/x.js to relevant handler
rewrite ^(.*.php)/ $1 last;
}

location ~ .php$ { ## Execute PHP scripts
if (!-e $request_filename) { rewrite / /index.php last; } ## Catch 404s that try_files miss

expires off; ## Do not cache dynamic content
fastcgi_keep_conn on;
fastcgi_pass unix:/var/run/hhvm/hhvm.sock;
fastcgi_index index.php;
fastcgi_param HTTPS $fastcgi_https;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param MAGE_RUN_CODE default; ## Store code is defined in administration > Configuration > Manage Stores
fastcgi_param MAGE_RUN_TYPE store;
include fastcgi_params; ## See /etc/nginx/fastcgi_params
}
}


3.My HHVM config file:

/etc/hhvm/server.ini

; php options

pid = /var/run/hhvm/pid

; hhvm specific

;hhvm.server.port = 9000
hhvm.server.file_socket = /var/run/hhvm/hhvm.sock
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


/etc/hhvm/php.ini

; php options

; hhvm specific
hhvm.log.level = Warning
hhvm.log.always_log_unhandled_exceptions = true
hhvm.log.runtime_error_reporting_level = 8191
hhvm.mysql.typed_results = false


Thank you for the kind sharing from:

http://bryanapperson.com/blog/intro-hhvm-mariadb-nginx-wordpress/
http://bryanapperson.com/blog/install-hhvm-nginx-ubuntu-14-04-make-wordpress-fly/
http://wiki.nginx.org/Install#Official_Debian.2FUbuntu_packages
https://udinra.com/blog/hhvm-fastcgi-nginx-speedup-php
http://stackoverflow.com/questions/23872439/nginx-rewrite-with-laravel-and-hhvm

3 comments:

  1. Caio Cesar IglesiasOctober 20, 2016 at 10:21 AM

    What magento version is that?

    ReplyDelete
  2. It is MAGENTO COMMUNITY EDITION ver 1.9.3.

    ReplyDelete