From 6cda801ec376021c7963a7933b63c1ecbd457f01 Mon Sep 17 00:00:00 2001 From: Sean Harvey Date: Fri, 10 Oct 2014 15:00:21 +1300 Subject: [PATCH] Adding documentation for installing HHVM with nginx on Linux --- docs/en/installation/index.md | 1 + docs/en/installation/nginx-hhvm.md | 102 +++++++++++++++++++++++++++++ 2 files changed, 103 insertions(+) create mode 100644 docs/en/installation/nginx-hhvm.md diff --git a/docs/en/installation/index.md b/docs/en/installation/index.md index e1d4a6fed..66c2a3ee0 100644 --- a/docs/en/installation/index.md +++ b/docs/en/installation/index.md @@ -28,6 +28,7 @@ To run SilverStripe on Linux/Unix, set up one of the following web servers: * [Install using Apache](webserver) - our preferred platform * [Install using Lighttpd](lighttpd) - fast, but a bit tricker to get going * [Install using Nginx](nginx) - Super fast at serving static files. Great for large traffic sites. +* [Install using nginx and HHVM](nginx-hhvm) - nginx and [HHVM](http://hhvm.com/) as a faster alternative to PHP ### Windows diff --git a/docs/en/installation/nginx-hhvm.md b/docs/en/installation/nginx-hhvm.md new file mode 100644 index 000000000..2bac39b25 --- /dev/null +++ b/docs/en/installation/nginx-hhvm.md @@ -0,0 +1,102 @@ +# nginx and HHVM + +[HHVM](http://hhvm.com/) is a faster alternative to PHP, in that it runs in a virtual machine +and uses just-in-time (JIT) compilation to achieve better performance over standard PHP. + +Installation on Debian or Ubuntu is relatively straightforward, in that HHVM already provide +packages available to use: + +Debian 7 (wheezy): + + wget -O - http://dl.hhvm.com/conf/hhvm.gpg.key | sudo apt-key add - + echo deb http://dl.hhvm.com/debian wheezy main | sudo tee /etc/apt/sources.list.d/hhvm.list + sudo apt-get update + sudo apt-get install hhvm + +Ubuntu 14.04 (trusty): + + wget -O - http://dl.hhvm.com/conf/hhvm.gpg.key | sudo apt-key add - + echo deb http://dl.hhvm.com/ubuntu trusty main | sudo tee /etc/apt/sources.list.d/hhvm.list + sudo apt-get update + sudo apt-get install hhvm + +Please see [Prebuilt Packages for HHVM on HHVM wiki](https://github.com/facebook/hhvm/wiki/Prebuilt%20Packages%20for%20HHVM) for more ways to install. + +Assuming you already have nginx installed, you can then run a script to enable support for +nginx and/or apache2 depending on whether they are installed or not: + + /usr/share/hhvm/install_fastcgi.sh + +For nginx, this will place a file at `/etc/nginx/hhvm.conf` which you can use to include in +your nginx server definitions to provide support for php requests. + +In order to get SilverStripe working, you need to create a custom configuration file. + +In your `/etc/nginx/silverstripe.conf`, add this configuration: + + fastcgi_buffer_size 32k; + fastcgi_busy_buffers_size 64k; + fastcgi_buffers 4 32k; + + location / { + try_files $uri /framework/main.php?url=$uri&$query_string; + } + + error_page 404 /assets/error-404.html; + error_page 500 /assets/error-500.html; + + location ^~ /assets/ { + sendfile on; + try_files $uri =404; + } + location ~ /(mysite|framework|cms)/.*\.(php|php3|php4|php5|phtml|inc)$ { + deny all; + } + location ~ /\.. { + deny all; + } + location ~ \.ss$ { + satisfy any; + allow 127.0.0.1; + deny all; + } + location ~ web\.config$ { + deny all; + } + location ~ \.ya?ml$ { + deny all; + } + location ^~ /vendor/ { + deny all; + } + location ~* /silverstripe-cache/ { + deny all; + } + location ~* composer\.(json|lock)$ { + deny all; + } + location ~* /(cms|framework)/silverstripe_version$ { + deny all; + } + +The above script passes all non-static file requests to `/framework/main.php` in the webroot which relies on +`hhvm.conf` being included prior so that php requests are handled. + +Now in your nginx `server` configuration you can then include the `hhvm.conf` and `silverstripe.conf` files +to complete the configuration required for PHP/HHVM and SilverStripe. + +e.g. `/etc/nginx/sites-enabled/mysite`: + + server { + listen 80; + root /var/www/mysite; + server_name www.mysite.com; + + error_log /var/log/nginx/mysite.error.log; + access_log /var/log/nginx/mysite.access.log; + + include /etc/nginx/hhvm.conf; + include /etc/nginx/silverstripe.conf; + } + +For more information on nginx configuration, please see the [nginx installation](nginx) page.