OneWheeledBicycle

Random mutterings of Alastair James

Using groovy with LAMP (via SCGI)

with 3 comments

I have been playing quite a bit with groovy and I am quite impressed. For those that dont know, its a java-like scripting language that adds many of the features you would expect from modern scripting languages such as Ruby and Python. Obviously this might be an interesting platform with which to develop web applications.

There is an existing web framework for groovy called grails (ho ho). However, it seems to require some XML-heavy, monster application server. Urg! In my mind that undoes any advantage of using a nice and simple language in the first place. What I really wanted was to be able to use groovy in a LAMP environment in the same way I might use (say) PHP. I.e. just throw a file (say index.groovy) into the docroot of my server and have it come up on the screen!

No out of the box method exists to do this (at least as far as I could find), so I set about writing my own. The basic design is a small Java program that acts a proxy between the webserver and the groovy scripts. The program runs in the background and communicates with the webserver via the Simple Common Gateway Interface (SCGI). I first of all tried getting it to work with FastCGI, but thats a much more complex specification and does not seems to offer that much performance boost!

Anyway, here is the distribution file: SCGIApplicationServer.zip, be aware its just a proof of concept and not complete! Note it includes the groovy distribution jar, so you should not need to download the separately.

To configure it you need to tell your webserver to treat .groovy files with a SCGI handler. This is how to do this in lighttpd (Apache is similar). Basically you edit your lighttpd.conf file so that “mod_scgi” is listed in the modules and uncommented. Something like:

server.modules = (
#"mod_rewrite",
#"mod_redirect",
#"mod_alias",
"mod_access",
"mod_scgi")

Then you add the following to the end of the file:


scgi.server = ( ".groovy" => (
(
"host" => "127.0.0.1",
"port" => 4444
)
))

The next step is to throw the ‘index.groovy’ file from the zip into your webservers docroot. Restart your webserver.

Finally, we need to start the SCGIApplicationServer program. Open a console in the unzipped directory and type:

java -jar SCGIApplicationServer.jar -port=4444

Then navigate to http://localhost/index.groovy in your browser. All being well you should see a welcome message on the screen!

As I said before, this is a work in progress. I will be updating (and releasing source code) soon…

Advertisement

Written by aljames

September 6, 2007 at 10:26 am

Posted in Coding, Groovy, Java, Tech

3 Responses

Subscribe to comments with RSS.

  1. this is great i’m in france looking check all things related to groovy on the web, since about 6 months . but i’m not an experience developper i’m just starting to lean Groovy and java both at same time in my school it’s java at home is groovy

    and your idea is really great ..keep up the good work

    kémèt

    September 6, 2007 at 7:23 pm

  2. hi there just dropping in to say Hellooo..

    lora lee

    October 24, 2007 at 10:39 pm

  3. I’m about to embark on the exact same project…to make an scgi app for executing groovy scripts. The idea is to use groovy for web development without using an java based app server. Any further progress on this ?

    David

    November 25, 2008 at 9:52 pm


Leave a Reply

Fill in your details below or click an icon to log in:

Gravatar
WordPress.com Logo

Please log in to WordPress.com to post a comment to your blog.

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.