1

I followed the instructions here at https://github.com/hhvm/hack-example-site and somehow lost my way when setting up hhvm hack site on ngnix over ubunut 14.04 . Please note that I used the appropriate apt-get repo for 14.04.

However after configuring and trying to access 127.0.0.1:9000 I see an error in the /var/log/hhvm/error.log

FastCGI protocol: received an invalid record

My /etc/ngnix/sites-enabled is as follows

-rw-r--r-- 1 root root  0 Aug 30 22:01 default
lrwxrwxrwx 1 root root 44 Aug 30 22:21 hack-example-site -> /etc/nginx/sites-available/hack-example-site

The contents of /etc/ngnix/sites-available/hack-example-site is as follows:

server {
  root ~/hack-example-site/hack-example-site;
  index index.php;
  location ~ \.php$ {
    # If fastcgi backend is on another server disable this.
    # Read issue #6 about this
    try_files $uri =404;

    fastcgi_pass  127.0.0.1:9000;
    fastcgi_index index.php;
    #fastcgi_param SCRIPT_FILENAME ~/hack-example-site/hack-example-site/index.php
    fastcgi_param ~/hack-example-site/hack-example-site        $document_root$fastcgi_script_name;
    include fastcgi_params;
  } 
}

Could someone please help me with this hhvm site running on my local host? Thanks.

Oh and please note the ngnix is installed properly and the server responds to localhost.

The configuration file /etc/nginx/sites-available/hack-example-site below:

server {
  root /root/hack-example-site;
  index index.php;
  server_name localhost;
  location ~ \.php$ {
# If fastcgi backend is on another server disable this.
# Read issue #6 about this
try_files $uri =404;

fastcgi_pass  127.0.0.1:9000;

fastcgi_index index.php;

#fastcgi_param SCRIPT_FILENAME ~/hack-example-site/hack-example-

site/index.php

fastcgi_param /root/hack-example-site 

$document_root$fastcgi_script_name;

include fastcgi_params;

} } ~

Anand
  • 355
  • 1
  • 2
  • 12
  • Thanks derp. When I say localhost, I don't get the index.php on the configured hhvm site. I don't understand why? Just add, running 'hhvm index.php' outputs the desired result, so I assume hhvm is installed and configured properly. – Anand Aug 31 '14 at 02:01
  • What DOES happen when you talk to the nginx port (80 or 8080 or wherever it's running)? Do you get an error, blank page, something else? Is nginx working? Is it having trouble talking to HHVM? Since HHVM is listening on 9000 and writing to the log, it doesn't look to be the immediate culprit. – Josh Watzman Aug 31 '14 at 03:12
  • @JoshWatzman, I get the page on /usr/share/nginx/html/index.html. I tried something different. I created a symbolic link on /etc/ngnix/sites-enabled/default -> /etc/nginx/sites-avaliable/default. And edited the /etc/nginix/sites-available/default with the following values on test hack server { listen 80 default_server; listen [::]:80 default_server ipv6only=on; root /usr/share/nginx/html; #index index.html index.htm; index test.php; # # # Make site accessible from http://localhost/ server_name localhost; include hhvm.conf; – Anand Aug 31 '14 at 03:30
  • Sorry for being messy in the comments. I will post the work around as a temporary solution. – Anand Aug 31 '14 at 03:34

1 Answers1

0

I did find a work around to test my hack scripts but not really satisfied with this. I created symbolic link

/etc/ngnix/sites-enabled/default->/etc/ngnix/sites-available/default.

Copied test.php which has simple hello world written in hack to /usr/share/nginx/html. Edit the /etc/nginx/sites-available/default as follows:

server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;

    root /usr/share/nginx/html;
    #index index.html index.htm;
    index test.php;
    # Make site accessible from http://localhost/
    server_name localhost;
    include hhvm.conf;

Now when I visited localhost, the hackscript was executed and Helloworld was shown.

However I would have liked this to work with /etc/nginx/sites-available/hack-site-example instead of default. Not sure what is going there? Can anyone throw some light?
Anand
  • 355
  • 1
  • 2
  • 12
  • What happens if, instead of this workaround, you symlink `/etc/nginx/sites-available/hack-site-example` to `/etc/nginx/sites-enabled/hack-site-example` -- or did you already do that? – Josh Watzman Aug 31 '14 at 04:43
  • (In particular, did you make sure you fully followed this section of the directions: https://github.com/hhvm/hack-example-site#set-up-the-nginx-config ?) – Josh Watzman Aug 31 '14 at 05:04
  • I removed the symlink to default and created a symlink for hack-site-example. Now I see permission denied in the /var/log/nginx/error.log 2014/08/31 18:08:46 [error] 9652#0: *1 "/root/hack-example-site/index.php" is forbidden (13: Permission denied), client: 127.0.0.1, server: localhost, request: "GET / HTTP/1.1", host: "localhost" – Anand Aug 31 '14 at 08:18
  • @JoshWatzman, I revisited the steps on the link carefully. Also tried a few other things but still couldn't make it work. I have changed the permissions but still the same result. I have pasted the configuration of the nginx file in the original issue description above for your reference. Thanks for your help – Anand Aug 31 '14 at 08:45
  • I think I am going to dive deep into nginx configuration here http://blog.martinfjordvald.com/2010/07/nginx-primer/ – Anand Aug 31 '14 at 09:13
  • I quit for the day. I am unable to make this work :( – Anand Aug 31 '14 at 10:05
  • Finally tried changing ownership of the files in hacksite to www-data as hhvm is started as www-data user. Even that didn't work. :( – Anand Aug 31 '14 at 10:31
  • 1
    If the "permission denied" is in the nginx log, it might be an nginx misconfiguration as opposed to HHVM not being able to read the file? Can nginx read the file? Try `sudo -u www-data -s` and see if you can reproduce the permission issue as well. – Josh Watzman Sep 02 '14 at 04:35
  • @JoshWatzman, Thanks. Yes I am able to reproduce the permission denied anand@anand-OptiPlex-980:~$ sudo -u www-data -s bash: /home/anand/.bashrc: Permission denied www-data@anand-OptiPlex-980:~$ – Anand Sep 06 '14 at 23:04
  • That's just an error from `bash` since I probably screwed up the way to invoke `sudo` like that slightly, I think it's safe to ignore. (Do you see how it's complaining about *your* bashrc, which is irrelevant to www-data?) Check the other things I mentioned above that are actually relevant to the webserver. – Josh Watzman Sep 07 '14 at 19:06