obdo32
By:
obdo32

How to configure FastCGI for HHVM on a LEMP server

June 15, 2014 8k views
I have been trying to get a LEMP server up and running with HHVM but after I install everything the install_fastcgi.sh always says: root@Threed:~# sudo /usr/share/hhvm/install_fastcgi.sh Checking if Apache is installed WARNING: Couldn't find Apache2 configuration paths, not configuring Checking if Nginx is installed Detected Nginx installation Checking for custom Nginx configuration WARNING: Detected clashing configuration. Look at /etc/nginx/hhvm.conf for information how to connect to the hhvm fastcgi instance. and then it stops there. I have done this on Ubuntu 14.04 and Debian 7 (and the Ubuntu LEMP image) but it never gets past this part. hhvm --version gives me 3.1.0 and i can run php commands with it so its gotta just be something with the fastcgi. I've been looking up how to deal with this but havent found any info on this problem (especially not in /etc/nginx/hhvm.conf) Was wondering if anyone could help me with this
4 Answers
To enable HHVM on Nginx, you need to add the contents of /etc/nginx/hhvm.conf to your server block. By default, you'd run:
sudo nano /etc/nginx/sites-enabled/default
and add the following inside the server directive:
location ~ \.(hh|php)$ {
    fastcgi_keep_conn on;
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include        fastcgi_params;
}
If you already had FastCGI up and running with php5-fpm, you'll need to remove or comment out its configuration. For instance, if you were using the LEMP one-click image, comment out the following:
#       location ~ \.php$ {
#               try_files $uri =404;
#               fastcgi_split_path_info ^(.+\.php)(/.+)$;
#               fastcgi_pass unix:/var/run/php5-fpm.sock;
#               fastcgi_index index.php;
#               include fastcgi_params;
#       }
Finally, remember to restart Nginx:
sudo service nginx restart
At the beginning, I also missed this part. There are actually two blocks of FPM configurations you have to comment out.
#       location ~ \.php$ {
#               try_files $uri =404;
#               fastcgi_split_path_info ^(.+\.php)(/.+)$;
#               fastcgi_pass unix:/var/run/php5-fpm.sock;
#               fastcgi_index index.php;
#               include fastcgi_params;
#       }

...

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
#       fastcgi_split_path_info ^(.+\.php)(/.+)$;
#       # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
#
#       # With php5-cgi alone:
#       fastcgi_pass 127.0.0.1:9000;
#       # With php5-fpm:
#       fastcgi_pass unix:/var/run/php5-fpm.sock;
#       fastcgi_index index.php;
#       include fastcgi_params;
#}

I followed the instructions, the system worked and I got a hip hop response on info.php, 1st time. When I cold start the server I have to restart the HHVM service to get results from info.php. Is there an explanation? thks!

I had neither of those segments in my file to comment out. And upon adding the suggested lines I'm not seeing any difference. Any advice is appreciated. Thank you!

Have another answer? Share your knowledge.