Apache2 REQUEST_FILENAME requires DOCUMENT_ROOT

I had a problem with my rewrite rules, that looked like this:

  DocumentRoot /var/www/trust.jj5.net
  RewriteEngine On
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule (.*) http://trust.jj5.net/sorry.html [L,R]

I was trying to redirect any request which didn’t match a file or directory. The !-f and !-d requirements were failing because the path to the REQUEST_FILENAME wasn’t fully qualified. I fixed the problem by including the DOCUMENT_ROOT:

  DocumentRoot /var/www/trust.jj5.net
  RewriteEngine On
  RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f
  RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-d
  RewriteRule (.*) http://trust.jj5.net/sorry.html [L,R]

Happy days! :)

dir2ogg (no chipmunks!)

Learned about dir2ogg over here and am using it to convert MP3 to OGG.

So… I installed dir2ogg:

# apt-get install dir2ogg

And then I ran it on some MP3s, and the generated OGG files sounded like chipmunks. I read the man page for dir2ogg and saw that it had an option for mp3-decoder. I tried specifying the lame decoder but it complained that it couldn’t find it, so:

# apt-get install lame

Then I ran dir2ogg with the following command and the ouput OGG files sounded proper!

$ dir2ogg --mp3-decoder=lame --quality=10 .

Happy days!

Creating a user and database in PostgreSQL

To create a database and user account for use on PostgreSQL:

root@devotion:~# su - postgres

postgres@devotion:~$ psql
psql (8.4.21)
Type "help" for help.

postgres=# create user "www-data" superuser;
CREATE ROLE

postgres=# create database mydb with owner "www-data";
CREATE DATABASE

postgres=# \c mydb
psql (8.4.21)
You are now connected to database "mydb".
                                            ^
mydb=# alter user "www-data" with password 'secret';
ALTER ROLE

Running Apache as ME!

On my development machine I want Apache to run under my user id so I can automatically generate files (and have permission to write them).

I configured Apache like this:

root@mercy:/etc/apache2# grep -R www-data .
./envvars:export APACHE_RUN_USER=www-data
./envvars:export APACHE_RUN_GROUP=www-data

root@mercy:/etc/apache2# vim envvars 

export APACHE_RUN_USER=jj5
export APACHE_RUN_GROUP=jj5

root@mercy:/etc/apache2# apache2ctl graceful
/var/lock/apache2 already exists but is not a directory owned by jj5.
Please fix manually. Aborting.

root@mercy:/etc/apache2# chown jj5:jj5 /var/lock/apache2

root@mercy:/etc/apache2# apache2ctl graceful

Easy-peasy!

Wait… that didn’t work. The problem was apache2ctl graceful didn’t pick up the new envvars file, this fixed it:

root@mercy:/etc/apache2# /etc/init.d/apache2 restart

UnsupportedClassVersionError in Closure

Today while Getting Started with the Closure Compiler Application I ran into the following trouble:

jj5@mercy:~/Desktop/compiler-latest$ java -jar compiler.jar --help

Exception in thread "main" java.lang.UnsupportedClassVersionError: com/google/javascript/jscomp/CommandLineRunner : Unsupported major.minor version 51.0
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:634)
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
        at java.net.URLClassLoader.defineClass(URLClassLoader.java:277)
        at java.net.URLClassLoader.access$000(URLClassLoader.java:73)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:212)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
Could not find the main class: com.google.javascript.jscomp.CommandLineRunner. Program will exit.

To fix the problem I installed jdk-7:

root@mercy:/home/jj5# apt-get install openjdk-7-dbg openjdk-7-demo openjdk-7-doc openjdk-7-jdk openjdk-7-jre