Running symfony standard edition on HHVM
In part one of this series we talked about "Getting started with HHVM" by getting a compiled version of HHVM running in a vagrant box. In this part we'll configure the HHVM webserver to run the symfony standard edition.
Quick recap
In the previous blog post we compiled the latest version of HHVM to get up and running. This was quite a process in order to get started. Two days after our blogpost the facebook team released HHVM 2.2.0. If you don't want to compile HHVM yourself, follow the instructions on the hhvm wiki to get HHVM installed on your favorite OS (for example ubuntu 12.04, 13.04 or 13.10). We have confirmed the steps we take in this blog post to work with the apt-get
installable release.
In the rest of this blog post we assume you have an installation of HHVM running in a VM with port 8080 forwarded to it. In order to do that last thing, add the following line to your Vagrantfile
:
config.vm.network :forwarded_port, guest: 8080, host: 8080
Setting up symfony standard
We'll start off with cloning our fork of the symfony-standard repository containing a few changes to get you up and running. We will continue with explaining the things we've changed. SSH into your VM and clone (make sure git is installed!):
$ git clone -b hhvm https://github.com/E1379/symfony-standard.git symfony-hhvm
Composer
We'll use composer to install the dependencies for the project. We considered running composer with PHP as cheating, so we'll do it with hhvm
instead. Composer needs a way to unzip distributions. At the time of writing HHVM does not have native support for zip (yet). Luckily composer can fall back to a shell based unzip
:
$ sudo apt-get install unzip
Now get and run composer:
$ wget https://getcomposer.org/composer.phar
$ cd symfony-hhvm
~/symfony-hhvm $ hhvm ../composer.phar install # Just hit <enter> on every question ;)
Server configuration
There is a minimum amount of configuration required to get the HHVM webserver running. For your convenience we pushed the final result in the repository you just cloned.
We'll configure the server to run on port 8080
and use the web/
directory of the repository as the root directory of the project:
Server {
Port = 8080
SourceRoot = /home/vagrant/symfony-hhvm/web/
}
Next we set up a virtualhost that matches all domains and rewrites every request .?
to the app_dev.php
app bootstrap file of the symfony standard edition.
VirtualHost {
* {
Pattern = .*
RewriteRules {
* {
pattern = .?
# app bootstrap
to = app_dev.php
# append the original query string
qsa = true
}
}
}
}
Finally we instruct HHVM how to serve static files:
StaticFile {
Extensions {
css = text/css
gif = image/gif
html = text/html
jpe = image/jpeg
jpeg = image/jpeg
jpg = image/jpeg
png = image/png
tif = image/tiff
tiff = image/tiff
txt = text/plain
php = text/plain
}
}
Symfony specific changes
While the standard edition seems to run out of the box, we did encounter issues with sessions on HHVM. A temporary workaround for this is to disable the custom session handler registered by the standard edition by default and use the "php bridge" session storage. In order to do so, add the following lines to app/config/config_dev.yml
under the framework
key:
framework:
session:
storage_id: session.storage.php_bridge
handler_id: ~
The session has to be started explicitly in our web/app_dev.php
file now. (While you're there you can also remove the "localhost only" restriction.) Add the following at the top of the file:
date_default_timezone_set('UTC'); // we don't want warnings
session_start(); // we boot the session ourselves as a workaround for now
Run the webserver
Now we're all set to run the webserver! Instruct hhvm
to run in server mode and use the configuration file we explained above.
$ cd symfony-hhvm
~/symfony-hhvm $ hhvm --mode server --config hhvm/hhvm.conf
mapping self...
mapping self took 0'00" (31589 us) wall time
loading static content...
searching all files under source root...
analyzing 27 files under source root...
..loaded 14730 bytes of gif files
..loaded 106 bytes of txt files
..loaded 13735 bytes of png files
..loaded 7263 bytes of php files
..loaded 16064 bytes of css files
loaded 51898 bytes of static content in total
loading static content took 0'00" (6412 us) wall time
page server started
all servers started
Head over to http://vagrant.hhvm.local.qandidate.it:8080/ to see the symfony standard edition running!
Final remarks
We are amazed about the small amount of changes we had to do in order to get the symfony standard edition running on HHVM. Congratulations to the HHVM team for getting to this point, but let's not stop here! Try out your favorite library/framework/internal project and provide feedback to the HHVM project to make it even more awesome!
As for this series, stay tuned. Next time we will blog about debugging your application with HHVM (and we feel it's a lot more easier than xdebug!).