Installation with HHVM
In this section you will learn how to set-up NGINX with HHVM and MongoDB.
However, this tutorial is not meant to be an all inclusive guide on how ito
run NGINX and HHVM in a production environment.
In this tutorial, we will be using a Debian system, with NGINX installed
through apt-get and HHVM installed from
source into /usr/local/hhvm/3.9.1
(with the binary being at
/usr/local/hhvm/3.9.1/bin/hhvm).
NGINX
We simply install NGINX by running apt-get install nginx-full. If this
fails to start, it is likely that you already have Apache running on the
same port. If that happens, you will see the following lines in
/var/log/nginx/error.log:
2015/09/29 10:19:27 [emerg] 22445#22445: bind() to 0.0.0.0:80 failed (98:Address already in use)
2015/09/29 10:19:27 [emerg] 22445#22445: bind() to [::]:80 failed (98: Address already in use)
If this happens, simple remove Apache by running apt-get remove
apache2.
HHVM
I have installed HHVM from a source build, mostly because I needed one with
some of my own patches and debug symbols. The folks at Facebook also provide
pre-built packages, which is probably what you *want* to use in production and
development. You can find them at the
HHVM Wiki.
You need to install the hhvmandhhvm-dev packages. The latter is needed so that we can
compile the MongoDB HHVM extension later on.
Because I installed from source, I had to do some extra work. I had to create
/var/run/hhvm:
> /etc/hhvm/php.ini
]]>
I also had to start HHVM as www-data user. For now, I am
running it in the foreground in server mode as
follows:
sudo -u www-data -s /usr/local/hhvm/3.9.1/bin/hhvm \
--mode server \
-vServer.Type=fastcgi \
-vServer.FileSocket=/var/run/hhvm/sock
Making NGINX talk to HHVM
Once HHVM runs, we need to tell NGINX how to talk to HHVM for
.php files. Although this is perhaps not the most clean way
of doing this, you can add the following snippet to
/etc/nginx/sites-enabled/default, just after the
location / { … } section:
After adding the snippet, you should restart NGINX:
Just to see that it all works now, we will create a project directory and
in there, we place a ``index.php`` file with a ``phpinfo()`` file:
Create the project directory: sudo mkdir -p
/var/www/html/my-first-projectChange permissions to your user: sudo chown derick.www-data
/var/www/html/my-first-project
Create the file /var/www/html/my-first-project/index.php.
From now on, I will not include the full path
/var/www/html/my-first-project/ when I mention file names.
Put the following content in this file:
]]>
Now in your browser, request the page
http://gargleblaster/my-first-project/index.php (but adjust the
hostname). This should then show a page starting with "HHVM Version 3.9.1"
followed by several tables with information.
MongoDB Driver for HHVM
The MongoDB driver is the part that links up the PHP in HHVM with the database
server. To install and register the driver with HHVM, you need to take the
following steps:
Download the latest driver from
https://github.com/mongodb-labs/mongo-hhvm-driver-prototype/releases.
At the moment, there is only hhvm-mongodb-1.0beta1.tgz
so we will be using this one in the examples.
Unpack the archive: tar -xvzf hhvm-mongodb-1.0beta1.tgzcd into the newly created directory: cd hhvm-mongodb-1.0beta1
Generate the configure files for the bundled libraries. For this to work,
you need to have the automake, autoconf and libtool packages
installed (through apt-get).
Generate the Makefile: hphpize && cmake .
Build the driver: make
Install the driver: sudo make install. This last step tells
you were it has installed the binary file mongodb.so. In my
case, it showed: Installing:
/usr/local/hhvm/3.9.1/lib/hhvm/extensions/20150212/mongodb.so
Now that the driver is installed, you need to enable it in HHVM. In order
to do this, you need to add the following lines to
/etc/hhvm/php.ini, swapping out my directory name for the
that showed when running make install:
After you have done that, you need to stop HHVM by pressing Ctrl-C in the
shell running HHVM, and then start it again as above:
In order to test that it works, we edit our index.php file,
and replace its contents with:
]]>
This should output something like:
string(9) "1.0beta1"
Further reading
Continue this tutorial by jumping to