In a
previous post, I explained how to customize the
Jaxer+Apache package one can download from Aptana. As I tend to do, I got a bit sick and tired of seeing port numbers in my URLs when developing. So, I took some time yesterday to integrate Jaxer with my local Apache. While this post is about integrating Jaxer with Apache on a Mac, it should apply fairly well to other 'nix flavors -- with some file names and locations being a significant difference between Mac and other 'nix variants. For Windows, you're on your own :).
On my Mac, I use a 32-bit Apache 2.2.8, which I installed via MacPorts. I've disabled the standard or default Apache installation that ships with OS X. I prefer this, as the default Apache install on a Mac isn't nearly as customizable as your own.
To start, download the Jaxer+Apache installer from the link above. Expand the archive (DMG for Macs) and follow the basic instructions to move the expanded folders/files to the appropriate location. For example, on a Mac, running the DMG results in a folder called Aptana_Jaxer that you drag/copy to your Applications folder. This is where Jaxer MUST live on a Mac.
What you've just downloaded is a self-contained Jaxer and Apache installation ("sandboxed", as it were) and you can stop here and just run Jaxer within its sandbox and have a good old time (Aptana has plenty of documents on doing this). There's an application, called Jaxer Launcher, that lets you start and stop your self-contained Jaxer+Apache server (runs on port 8081).
To get started, open Jaxer Launcher and start Jaxer (and Apache). This will create some default folders that Jaxer uses (logs, etc.).
The following are the steps I took so that I could run Jaxer with my regular Apache installation.
Separate Jaxer from its own Apache instance:
Initially, you need a way to divorce the two sandbox servers when running the Jaxer Launcher. In the Aptana_Jaxer folder, there is a subfolder called scripts. Open this folder, locate the file "start.sh", and open it in the editor of your choice (I use TextMate for little edits like this). Simply comment out the last line in the file, like so (adding a pound sign, #, before the declaration): # $JAXERBASE/scripts/startApache.sh
This will prevent the Jaxer launcher from starting its own instance of Apache.
Instruct Apache to use Jaxer:
This is where I spent a good bit of time dealing with the integration of my preferred instance of Apache and Jaxer. In the end, it came down to adding just a few lines of code to my Apache httpd.conf file.
Start by opening the Apache configuration file, httpd.conf folder (mine is in /opt/local/apache2/conf/) in an editor of your choice.
Locate the Directory element that references your web root folder. For example, mine is:
<Directory>
# ...
</Directory>
Just before this element, add the following line of code:
Include /Applications/Aptana_Jaxer/jaxer/confs/jaxer-mac.httpd.conf
This instructs Apache to include the necessary Jaxer configuration files. You don't need to change anything in this file for Apache.
There are configuration files for each system (Mac, Windows, Linux) in the Aptana_Jaxer/jaxer/confs/ folder. For those of you on Linux or Windows, you would reference an alternate file in the above code.
Next, you need to add a couple lines of code inside the Directory element I noted above. The code is as follows:
JaxerFilter .html .xhtml .htm .php
JaxerFilterContentType text/html application/xhtml+xml
Adding these lines instructs Apache to filter .xhtml, .html, .htm, and .php files with the Jaxer server (i.e., it's how your Jaxer files get processed).
The changes to my Apache httpd.conf file now look like this:
<Directory>
Include /Applications/Aptana_Jaxer/jaxer/confs/jaxer-mac.httpd.conf
Options Indexes FollowSymLinks MultiViews
AllowOverride All
JaxerFilter .html .xhtml .htm .php
JaxerFilterContentType text/html application/xhtml+xml
Order allow,deny
Allow from all
</Directory>
The Drawbacks:
1. There is one drawback I found to doing this. If you don't have Jaxer running, you'll get a 500 error when you try to access any of the sites on your server. This is because Apache is trying to filter the pages through the Jaxer server and it's not running.
2. I haven't been able to make Jaxer start on system start-up (all my attempts thus far fail). However, I did tell OS X to start the Jaxer Launcher application on login so I just click the button to start the Jaxer server and I'm good to go. Not too much of a pain in the butt since both the Jaxer server and launcher fire up fast (lightweight). I'm looking for a permanent solution for this and will post as soon as I have it.
NOTES:
1. If you have installed a 64-bit version of Apache, be sure to follow Aptana's instructions to compile the Jaxer connector as a 64-bit connector (good instructions in the setup section of the
Jaxer guide for doing this).
2. Check back later today or tomorrow for a post about further customizing this based on Virtual Hosts and not having all requests run through Jaxer.