Installing Aptana Jaxer on Ubuntu

It's much easier than you'd think!
Install Aptana Jaxer on Ubuntu

It’s been a while since I’ve written about Jaxer, and it’s a shame, because there’s been a lot of major changes over the past several months. Anyway, I’ve been getting back into server-side javascript hacking, and found myself needing to get Jaxer up and running on a local dev server (and subsequently this one). You could also always work with Jaxer in Aptana’s cloud, where you’d get all the benefits of Jaxer integration with Aptana Studio and deployment workflows (SVN, staging, production, and just plain awesomeness) if you don’t want to (or need to) install Jaxer yourself. However, my needs (and presumably yours) required me to go down this route.

So, before we get started, let’s go over the list of prerequisites and assumptions:

  • You’re on Ubuntu 8.04 (newer versions should work the same as well)
  • You’ve got Apache installed (via aptitude, or you will have to adjust paths accordingly)
  • You’ve got root access to your server

That’s about it. MySQL is also good to have, but not required. Last thing before we start: many of the steps outlined here came from this site, which was contributed by a Jaxer user at Aptana’s forums. Right, let’s get busy…

Step 1: Get Jaxer

As you would expect, the first thing we’ll do is grab the latest version of Jaxer. However, before we do so, let’s make sure we know whether we’re on a 64 or 32-bit version of Ubuntu. Easy enough, from the command line:

uname -a

which outputs something like:

Linux genxdesign 2.6.24-19-xen #1 SMP Sat Jul 12 00:15:59 UTC 2008 x86_64 GNU/Linux

You can see, in my case I’m on 64 bit, as indicated by the “x86_64″. Now that we’ve got that, we can head over to http://aptana.com/jaxer/download, and grab the appropriate linux distribution. Easiest way to do so is to right-click on the link, select “Copy link location”, and then use it in the following command on your sever:

wget [pasted url]

Of course, you could also download it locally, then unzip and upload it to your server. I am assuming that you’re doing all this in your home directory on the server. Note also that the way the downloads work with Jaxer currently may give you a goofy file with wget. For example, at the time of writing, my wget url was “http://ec2-67-202-37-218.compute-1.amazonaws.com/downloads/jaxer/ubu64/Jaxer_package_withApache.zip?version=1.0.1.4310&cb=1000″ which gave me a file called: “Jaxer_package_withApache.zip?version=1.0.1.4310″ on the file system. Not an issue, I can fix this by doing:

mv Jaxer_package_withApache.zip\?version\=1.0.1.4310 jaxer.zip

Finally, on the server, simply type:

unzip jaxer.zip

to unzip the file.

Once the file’s unzipped or uploaded to your server, we’ll need to move the contents to their final home in /opt. So, back in your home directory:

sudo mv AptanaJaxer/ /opt

and we’re golden!

Step 2: Get the Mozilla Stuff

This is a bit easier than grabbing Jaxer itself, just one command:

sudo apt-get install firefox-3.0-dev firefox-dev

which we’ll follow with on more to make sure our libraries line up properly:

sudo ln -s /usr/lib/libexpat.so.1 /usr/lib/libexpat.so.0

That’s all we’ve got to do for Mozilla. Onward…

Step 3: Configure and Start

Believe it or not, we’re nearly done. At this point, we need to slurp out the Apache module configs from the Jaxer directory, and put them in the appropriate place for our Apache on Ubuntu. Two simple commands will take care of this:

sudo sh -c "grep '^LoadModule' /opt/AptanaJaxer/jaxer/confs/jaxer-linux.httpd.conf > /etc/apache2/mods-available/jaxer-linux.httpd.load"
sudo sh -c "grep -v '^LoadModule' /opt/AptanaJaxer/jaxer/confs/jaxer-linux.httpd.conf > /etc/apache2/mods-available/jaxer-linux.httpd.conf"

Now that we’ve got the module configs in the right place, we can enable the module for Apache by doing the following:

sudo a2enmod jaxer-linux.httpd

It will tell you that you need to reload apache. Don’t do that just yet. First, we need to let Jaxer create some directories, so let’s start Jaxer:

sudo JAXERBASE=/opt/AptanaJaxer /opt/AptanaJaxer/scripts/startJaxer.sh

Don’t worry about any warnings you see, those are just about Jaxer setting things up for the first time (similar to the first run of MySQL in a fresh install). We can go ahead and stop jaxer now, and then restart Apache:

sudo JAXERBASE=/opt/AptanaJaxer /opt/AptanaJaxer/scripts/stopJaxer.sh
sudo /etc/init.d/apache2 restart

if you don’t get any warnings or errors from Apache, go ahead and start Jaxer again:

sudo JAXERBASE=/opt/AptanaJaxer /opt/AptanaJaxer/scripts/startJaxer.sh

and you should be all set! If there aren’t any errors being spit out by anything, you can now browse to the Jaxer url on your server: http://yourdomain.com/aptana, and then run the server diagnostics. If everything’s working right, you’ll see some spinners, and then a screen that looks similar to this one:

Jaxer Server Diagnostics
click image for larger view

Just a few more things to do now…

Step 4: Configure Apache

Well, what we’ve currently got is Jaxer set up and running properly, but it isn’t set up for any of our sites. To do this, you’ll have to add a few lines to your vhost configuration(s) wherever you’d like Jaxer to actually run on your web site. For this example, I’ll assume you’re using the “default” site that comes with the standard Apache install on Ubuntu, but you can simply put these lines wherever you need them in your vhost files.

So, what we’re basically going to do here is tell Apache to use Jaxer as a filter for certain files in our web site. We do this by adding some directives in the appropriate “” area of our config. Let’s take a look at what a typical config might look like. If you type the following:

sudo vi /etc/apache2/sites-available/default

we’re looking for a section of the file that looks like:

<Directory /var/www/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All 

        Order allow,deny
        allow from all
</Directory>

Yours will probably be a bit different, but we’re basically looking for the directory directive that refers to the document root for this vhost (’/var/www’ in this case). Once you’ve located that, you need to add the following lines anywhere in there:

JaxerFilter html xhtml htm php
JaxerFilterContentType text/html application/xhtml+xml

What we’ve done is told Apache to run any html, xhtml, or php page through Jaxer as a filter (which is what we typically want). Once you’ve added these lines, you can stop Jaxer, restart Apache, and start Jaxer again:

sudo JAXERBASE=/opt/AptanaJaxer /opt/AptanaJaxer/scripts/stopJaxer.sh
sudo /etc/init.d/apache2 restart
sudo JAXERBASE=/opt/AptanaJaxer /opt/AptanaJaxer/scripts/startJaxer.sh

And that’s all there is to it!

A Few More Things…

Now that we’ve got everything running properly, I wanted to share a script to make starting / stopping Jaxer a bit easier, and a gotcha with URL re-writes you need to watch out for.

First, the control script. I am by no means a bash guru, and this script could use some major improvement. If you would like to improve upon it, let me know, I’d greatly appreciate it. Anyway, it does get the job done just fine. So, let’s go ahead and install it:

wget http://www.gen-x-design.com/downloads/jaxer_control.txt
sudo cp jaxer_control.txt /etc/init.d/jaxer
sudo chmod +x /etc/init.d/jaxer

Now, you can simply type “sudo /etc/init.d/jaxer [start|stop]” to start or stop Jaxer! Much easier than remembering that crazy sh file location.

Second, URL re-write gotchas. When I installed Jaxer on this server, I discovered the wordpress rewrite rules were breaking some special Jaxer urls needed for everything to function properly. Here’s what a typical offending set of rewrite rules could look like (in a .htaccess file, for example):

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

Well, this breaks Jaxer, because the URL rewrites take precedence over the LocationMatch directives in the jaxer module configuration. As I said, we can luckily fix this problem by adding one line, thus making our rewrite rules look like:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/jaxer-.*\b
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

So that the special Jaxer URLs aren’t redirected (in this case) to index.php.

Wrapping Up

And that’s it! Hopefully you find this quick and easy, and then you can get started with Jaxer, thus discovering how damn cool server-side javascript is. If you’d like to learn more about Jaxer, or need help, here are some useful URLs:

Other's Thoughts   (8 so far...)


  • Petter Sundnes
    Feb 21 '09 at 10:40 am

    This was a brilliant guide, I got up and running with Jaxer on my Linode based server in no time. Thanks!

    I ended up spending more time figuring out how vi works than the rest of the setup time took, so I ended up installing nano immediately after setting up Jaxer :)


  • Ian
    Feb 22 '09 at 9:37 pm

    Awesome, glad I could help :)


  • colin
    Mar 4 '09 at 7:12 am

    Kudos from me as well; it’s great when you can just copy and paste the commands, and they work AS IS. I’m not a server guru, just a code monkey, so it’s great to have these guides out there.

    Why did you register php to go to the JaxerFilter?


  • Ian
    Mar 4 '09 at 9:12 am

    Thanks!

    I added PHP to the filter so I could also use Jaxer within my PHP applications as well. It lets you start doing some pretty cool stuff :)


  • Nick Tulett
    Apr 22 '09 at 12:42 pm

    Thanks from me, too – could not work it out from the official docs and got no response on the forum till I found a link to this. Ta.


  • quickredfox
    May 19 '09 at 5:21 am

    Thanks a lot, you managed to smooth a few kinks out of this tedious task but for me one problem remains, Whenever I try to use the jaxer-service stuff, i get weird bugs and this seems to pop up in the logs:

    “Jaxer is the handler for this request but it’s not a callback or other recognized request type.”

    Any tips?


  • Bob
    Jun 3 '09 at 5:58 am

    Hi,
    You should also run:
    “sudo update-rc.d jaxer defaults 90 10″
    after you have created the /etc/init.d/jaxer script.
    This simply registers jaxer to start before apache2 (which usually starts at sequence number 91 at default runlevels) and to kill jaxer after apache2 (which usually is killed at sequence number 09 at default runlevels).
    This way, if you reboot the system, it will all load properly.


  • Bob
    Jun 3 '09 at 6:16 am

    Also thought I’d share my updated version of the init.d script.
    A few changes: JAXERBASE need only be exported once, and I’ve implemented commands as functions so they can be extended and so we can add a restart command.

    #!/bin/sh
    . /lib/lsb/init-functions

    export JAXERBASE=/opt/AptanaJaxer
    jaxer_start ()
    {
    /opt/AptanaJaxer/scripts/startJaxer.sh
    }
    jaxer_stop ()
    {
    /opt/AptanaJaxer/scripts/stopJaxer.sh
    }
    jaxer_restart ()
    {
    jaxer_start
    jaxer_stop
    }

    case “$1″ in
    start)
    jaxer_start
    ;;
    stop)
    jaxer_stop
    ;;
    restart|reload)
    jaxer_restart
    ;;
    *)
    log_success_msg “Usage: /etc/init.d/jaxer {start|stop|restart|reload}”
    exit 1
    ;;
    esac

  • Share Your Thoughts...

    Some HTML is ok. If this is your first comment on my site, it will be reviewed before being posted publicly. Your comment may be edited or marked as spam if it appears intended for SEO purposes.