== Requirements ==

- cabal
  * See quick installation instructions at the bottom of 
     http://hackage.haskell.org/trac/hackage/wiki/CabalInstall

- FastCGI development kit
  * MacPorts: sudo port install fcgi

- Haskell packages: fastcgi, json, utf8-string
  * cabal install fastcgi json utf8-string

- GF installed as a Cabal package
   * (cd ../.. && cabal install)
   * Maybe need to remove "-beta" from the Version field in ../../GF.cabal

== Building ==

- Build gf.fcgi

$ make

- Build small example grammar:

$ make food



== Running (lighttpd) ==

- Install lighttpd
  - MacPorts:
  $ sudo port install lighttpd

- Run lighttpd:
  $ lighttpd -f lighttpd.conf -D

- First test from the command-line, since debugging is harder from the AJAX UI:
  $ curl 'http://localhost:41296/gf/translate?input=this+fish&cat=Item&from=FoodEng'


- Go to http://localhost:41296/simple-client.html in your web browser.


== Running (Apache) ==

- Make sure that your web server supports FastCGI. For Apache on OS X,
  do this:

$  curl -O http://www.fastcgi.com/dist/mod_fastcgi-2.4.6.tar.gz
$  tar -zxf mod_fastcgi-2.4.6.tar.gz 
$  cd mod_fastcgi-2.4.6/
$  apxs -o mod_fastcgi.so -c *.c
$  sudo apxs -i -a -n fastcgi mod_fastcgi.so

- Make sure that your web server knows that gf.fcgi is a FastCGI
program.

- Make sure that you are allowed to run FastCGI programs in the 
directory that you use.

- With large grammars, gf.fcgi may take long enough to start that the web server
thinks that the program has died. With Apache, you can fix this by adding 
"FastCgiConfig -startDelay 30" to your httpd.conf. 

These sections from my Apache config fixes the above two 
(some of this may be fixed by the second apxs command above):

(On OS X, this is in /etc/httpd/httpd.conf)

LoadModule fastcgi_module     libexec/httpd/mod_fastcgi.so
AddModule mod_fastcgi.c

<IfModule mod_fastcgi.c> 
  FastCgiIpcDir /tmp/fcgi_ipc/ 
  AddHandler fastcgi-script .fcgi 
  FastCgiConfig -startDelay 30
</IfModule>


(On OS X, this is in /etc/httpd/users/bringert.conf)

<Directory "/Users/bringert/Sites/">
    Options Indexes MultiViews FollowSymlinks ExecCGI
    AddHandler cgi-script .cgi
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>

- If you have changed the web server config, you need to restart the web server
 (this is also useful to get a clean slate if you end up with dead or resource-hogging 
 FastCGI processes):

$ sudo apachectl restart

- If Apache complains about a syntax error on the FastCgiIpcDir line, try deleting
  any existing /tmp/fcgi_ipc/ directory:

$ sudo rm -rf /tmp/fcgi_ipc/

- Copy or symlink this directory to your web directory.

- First test from the command-line, since debugging is harder from the AJAX UI:

$ curl 'http://localhost/~bringert/gf-server/gf.fcgi/translate?input=this+fish&cat=Item&from=FoodEng'

- Check server logs (e.g. /var/log/httpd/error_log) if it doesn't work.

- Go to SERVER_URL/simple-client.html in your web browser.
