HHVM Nginx Ubuntu with multiple Site

HHVM Nginx Ubuntu with multiple Site

To run HHVM on Nginx with Ubuntu 14.04 and multiple Site per Server you can use this Howto. I work with Nginx variables, this make it easy to have short Nginx configs.

First step is to install HHVM on the server

sudo apt-get install software-properties-common

sudo apt-key adv --recv-keys --keyserver hkp:// 0x5a16e7281be7a449
sudo add-apt-repository 'deb trusty main'
sudo apt-get update
sudo apt-get install hhvm

Now you get the following information

* HHVM is installed.
* Running PHP web scripts with HHVM is done by having your webserver talk to HHVM
* over FastCGI. Install nginx or Apache, and then:
* $ sudo /usr/share/hhvm/
* $ sudo /etc/init.d/hhvm restart
* (if using nginx)  $ sudo /etc/init.d/nginx restart
* (if using apache) $ sudo /etc/init.d/apache restart
* Detailed FastCGI directions are online at:
* If you're using HHVM to run web scripts, you probably want it to start at boot:
* $ sudo update-rc.d hhvm defaults
* Running command-line scripts with HHVM requires no special setup:
* $ hhvm whatever.php
* You can use HHVM for /usr/bin/php even if you have php-cli installed:
* $ sudo /usr/bin/update-alternatives --install /usr/bin/php php /usr/bin/hhvm 60

Now run the install script

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

So now you have install the HHVM. Now you must setup the multiple instances.

sudo cp /etc/init.d/hhvm /etc/init.d/hhvm_www_safematix_com
sudo cp /etc/default/hhvm /etc/default/hhvm_www_safematix_com
sudo cp /etc/hhvm/server_www_canus_at.ini /etc/hhvm/server_www_safematix_com.ini

Now you must edit the configs.


sudo vi /etc/init.d/hhvm_www_safematix_com


## This is a configuration file for /etc/init.d/hhvm.
## Overwrite start up configuration of the hhvm service.
## This file is sourced by /bin/sh from /etc/init.d/hhvm.

## Configuration file location.
## Default: "/etc/hhvm/server.ini"
## Examples:
##   "/etc/hhvm/conf.d/fastcgi.ini" Load configuration file from Debian/Ubuntu conf.d style location

## User to run the service as.
## Default: "www-data"
## Examples:
##   "hhvm"   Custom 'hhvm' user
##   "nobody" RHEL/CentOS 'www-data' equivalent

## Add additional arguments to the hhvm service start up that you can't put in CONFIG_FILE for some reason.
## Default: ""
## Examples:
##   "-vLog.Level=Debug"                Enable debug log level
##   "-vServer.DefaultDocument=app.php" Change the default document

## PID file location.
## Default: "/var/run/hhvm/pid"


; php options

pid = /var/run/hhvm/pid_www_safematix_com

; hhvm specific 

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

Now edit the nginx settings

location ~ \.(hh|php)$ {
    fastcgi_keep_conn on;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include        fastcgi_params;

vhost config

server {
	listen [2a01:4f8:210:3101::12]:443 ssl spdy;
	listen 443 ssl spdy;
	spdy_headers_comp 5;


	root /srv/www/www_safematix_com/htdocs;
	index index.php index.html index.htm;

	access_log   /srv/www/www_safematix_com/log/www.safematix.com_ssl.access.log;
        error_log    /srv/www/www_safematix_com/log/www.safematix.com_ssl.error.log;

        ssl_certificate /etc/nginx/ssl/safematix/;
        ssl_certificate_key /etc/nginx/ssl/safematix/;

        ssl_dhparam /etc/nginx/ssl/safematix/;

	set $siteport 9001;

	include global/ssl.conf;
	include global/restrictions.conf;
	include global/wordpress.conf;
	include global/php.conf;

Now enable HHVM at boot and reload service

sudo update-rc.d hhvm_www_safematix_com defaults
sudo service hhvm_www_safematix_com start
sudo service nginx reload




External Links:

3 thoughts on “HHVM Nginx Ubuntu with multiple Site”

  1. Thanks for the instructions. They are very helpful

    Note the following command:
    sudo update-rc.d hhvm_www_safematix_com defaults did not work

    Resulted in the following error:
    insserv: script hhvm_www_safematix_com: service hhvm already provided!
    insserv: exiting now!
    update-rc.d: error: insserv rejected the script header

    To fix open the following file:
    sudo nano /etc/init.d/hhvm_www_safematix_com

    And make the following edits:
    # /etc/init.d/hhvm_www_safematix_com — startup script for HHVM FastCGI
    # Provides: hhvm_www_safematix_com

    Of course your website will be named differently, I kept the fix relevant to the instructions above.


Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.