Ever since I heard about the incredible performance gains possible by using HHVM instead of PHP’s native interpreter, I’ve dreamed of getting this working for some of my larger e-commerce client sites that struggle with performance.
This past labor day, I moved to using ServerPilot.io (again, it’s awesome, get it. now) to manage my servers. It installs a LAMP + LEMP stack by default, but being as awesome as they are, ServerPilot includes a doc that shows you how to setup a LEMP only configuration on their stack.
After using this for a few months, I decided to look into running HHVM on this server, but only for wp-admin requests. My logic is that it is easy to cache frontend pages, but it’s hard to optimize WP admin. And for e-commerce sites, WP admin becomes a regular web application for people who process orders and deal with customers.
It turns out that there are a ton of guides available for setting up HHVM, but not many for setting it up for only certain urls (ie., wp-admin). Accomplishing this took a lot of trial and error. Nginx location directives operate on a best match scheme, so it was difficult to find a configuration that functioned with IF / ELSE logic, especially since Nginx does not allow fastcgi directives within an actual if / else block.
I eventually discovered that you can nest location directives, and that nested rules actually run isntead of the outer directive if they match. This solved my dilemma well, and the rest was easy to setup.
Here is the configuration I ended up with:
If you need help installing HHVM, I highly recommend this guide, especially if you are operating within a ServerPilot managed environment. It is a very lean install plan that reduces greatly the chance of breaking something important:
Setup Hack and HHVM on Digital Ocean
Feel free to ask questions. I’ll do my best help.
Alister Cameron (@alicam) says
What I really want to see is a version of WordPress with added “Hacks” to optimise performance with proper typing, etc. Wonder what the performance gains might be…
jc says
I think you are the first person to attempt hhvm on serverpilot and succeed it, I tried my self and failed, I kept getting blank pages..
Would you happen to know away to run hhvm for entire site ? not just wp-admin on serverpilot?
Thanks!
Clifton Griffin says
You would use this instead: https://gist.github.com/clifgriffin/a74672daa0356eb737cd
Ayub Lin says
Hi Clif,
Thanks for the straight forward and simple tutorial. I assume you changed the default serverpilot setup to work without Apache?
Mine is default, only implemented Varnish on serverpilot, did it as instructed here:
https://serverpilot.io/community/articles/how-to-install-and-configure-varnish.html
So it became:
Browser –> Nginx –> Varnish –> Apache –> PHP-FPM
Do you have any idea how would I replace PHP-FPM with HHVM in that case?
willcm says
Hi – I’m clearly being dumb – I’ve pasted your config file above into /etc/nginx-sp/core.d/ and when I restart nginx I get this error:
Restarting nginx-sp: nginx: [emerg] “location” directive is not allowed here in /etc/nginx-sp/core.d/main.custom.conf:1