Jaxer working with Vanilla Apache

Getting Jaxer to work with vanilla Apache (as in installed from apt-get or yum) is something that I haven’t been able to get working, probably because I’m an idiot. After the failure of not being able to register our compiled version of Apache to Systemd, I figured I might as well try getting vanilla Apache to work with Jaxer, and if it doesn’t work I can always go cry in a corner.

I guess the corner will have to wait for another opportunity, because Jaxer (quite unexpectedly) worked with vanilla Apache, and quite nicely at that. So what exactly is the problem before versus now? The main reason is likely going to be envvars, but I can’t say exactly, since I didn’t have the context of reverse engineering Apache when I edited the conf files praying that something would work.

While I can’t describe the issue of what was wrong before, I can describe the process that it takes to get Jaxer working with vanilla Apache. So let’s be sure to record the steps here as to be able to take advantage of it later.

$ sudo apt-get update
$ sudo apt-get install apache2 -y

Like any Apache install we update and then install Apache2. Note that we’re only interested in static file server, so we don’t need to grab php7 or MariaDB for a LAMP install at the moment. Assuming that port 80 isn’t in use, Apache should automatically start and be listening for requests. But we need to configure a few things first, so we’ll stop the file server with

$ sudo systemctl stop apache2

First we take our jaxer.httpd.conf file and copy it into /etc/apache2/mods-available. Then we need to enable it with:

$ sudo ln -s /etc/apache2/mods-available/jaxer.httpd.conf /etc/apache2/mods-enabled/

Next we need to edit the envvars file to include the variables that Jaxer defines (and probably needs to be able to run). So next we edit the file /etc/apache2/envvars and add the following text to the end of the file.

if test "x$LD_LIBRARY_PATH" != "x" ; then
  LD_LIBRARY_PATH="/opt/AptanaJaxer/Apache22/lib:$LD_LIBRARY_PATH"
else
  LD_LIBRARY_PATH="/opt/AptanaJaxer/Apache22/lib"
fi
export LD_LIBRARY_PATH
export JAXERBASE=/opt/AptanaJaxer
export ANCHOR=/opt/AptanaJaxer

Then we save the file and then update the variables with:

$ source /etc/apache2/envvars

Though to be honest, I’m not sure if this step is actually needed or if the variables are automatically read with systemctl start or stop. Next we need to set the file root to /opt/ApatanaJaxer/public. This is something that I would like to test to see if it can be changed, but for right now we’ll stick with what works. So to change the web root directory we’ll edit /etc/apache2/sites-enabled/000-default.conf to change the root directory.

<VirtualHost *:80>
        # The ServerName directive sets the request scheme, hostname and port that
        # the server uses to identify itself. This is used when creating
        # redirection URLs. In the context of virtual hosts, the ServerName
        # specifies what hostname must appear in the request's Host: header to
        # match this virtual host. For the default virtual host (this file) this
        # value is not decisive as it is used as a last resort host regardless.
        # However, you must set it for any further virtual host explicitly.
        #ServerName www.example.com

        ServerAdmin webmaster@localhost
        DocumentRoot /opt/AptanaJaxer/public

        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        # For most configuration files from conf-available/, which are
        # enabled or disabled at a global level, it is possible to
        # include a line for only one particular virtual host. For example the
        # following line enables the CGI configuration for this host only
        # after it has been globally disabled with "a2disconf".
        #Include conf-available/serve-cgi-bin.conf

</VirtualHost>

Next for the purposes of debugging we’ll edit the Apache config file to serve directories, and we’ll also remove the deny from all cause on the root directory. To be honest I find it weird that the default /var/www/html configuration works with this clause, but it seems like anytime I change something it can be fixed by removing that line. So while it might not be a good idea for production reasons, it works now so we’ll go with it. Edit /etc/apache2/apache2.conf and change the root directory configuration to:

<Directory />
        Options Indexes FollowSymLinks
        AllowOverride None
        #Require all denied
</Directory>

And then since Apache uses the user and group name of www-data, we need to change the owner of /opt/AptanaJAxer/public to www-data, otherwise Apache won’t be able to read the files.

$ sudo chown -R www-data:www-data /opt/AptanaJaxer/public

And with that, we’re ready to start Apache again. Start the server with:

$ sudo systemctl start apache2

And if everything works, then Jaxer should be working with vanilla Apache. In this case we tested the Todo List and it worked!

So there are a lot of things to be excited about with this development. It means that we can really get rid of the Apache22 and scripts file in the post install directory leaving just jaxer and public. And it also means that we don’t have to completely rely on our Nodejs emulation of apache that could run into issues for the non-implemented parts of the server emulation. I think this is the implemented we’ll be using in the install script going forward. And it means that the next thing we can test is to see if we can move the root directory from /opt/AptanaJaxer/public to /var/www/html. Which would only leave the jaxer folder left in the runtime enviornment.

Edit:
I decided to push my luck to see if I could move the publuc folder from /opt/AptanaJaxer/public to /var/www/html. And on first glance it looks like it worked! We were able to get our Todo list application running from the standard Apache public directory. I think one more think we need to test to see if relative paths for server-side scripts work. As that’s something that Jaxer might get confused with loading.

Edit2:
Changed the Todo sample application to use jaxer-include instead of inline scripts, and the application still works inside of the /var/www/html folder. Which means the only folder left in the post install application is /opt/AptanaJaxer/jaxer. Which means our next focus will be moving that directory to /etc/emrajs.