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:
Feel free to ask questions. I’ll do my best help.