Saturday, October 2, 2010

How to build mod_v8 in Ubuntu

mod_v8 is a simple Apache module which enable Server Side JavaScript(SSJS) support in Apache Server. It uses Google V8 engine for the JavaScript execution. What this module basically does is, it adds a Handler for a particular file extension(.v8) and then, those files are treated as SSJS files which then get executed via V8 engine.

While I was building this amazing mod_v8 module, I had to do small modification to the process. So I though it might be worth to have a post with the steps I followed.

1. Checkout V8 development branch
svn checkout v8

2. Build V8 using scons with the library=shared option. Optionally you might need to add arch option too. You can find more info about it at Building V8 in Ubuntu 64 bit
scons library=shared arch=x64

3. Assuming your v8 checkout is at /home/wageesha/v8, building process will create following obj, etc.. directories and files within v8 directory. You need to copy this into /usr/lib.
cp ~/wageesha/v8/ /usr/lib

4. Checkout mod_v8 code
svn checkout mod_v8

5. Build mod_v8 using scons. Depending on your scons version, you might need to change
opts = Options('') into opts = Variables('')
opts.Add(PathOption(....)) into opts.Add(PathVariable(....))

in the SConstruct. Further, if you haven't copied into the /usr/lib directory as in step 3, build process will fail saying
/usr/bin/ld: cannot find -lv8

6. Then open /etc/apache2/apache2.conf and add following lines, with the correct path to
LoadModule v8_module /home/wageesha/mod_v8/trunk/

<IfModule mod_v8.cpp>
#Adds the v8 handler
AddHandler v8-script .v8

7. Copy /home/wageesha/mod_v8/trunk/test.v8 into /var/www folder.

8. Restart apache and access test.v8

which will then print
Hello World!

in the browser.

No comments:

Post a Comment