Music - the symphonic phenomenon that binds all us Humans and maybe even separates us from the lower lifeforms - is something I've been forgetting over the past two years. The last two years I've been very focussed on my career and I haven't spend much time downloading or listening to music. Since my rock teenager days my passion for music has been decreasing. The only moments of music for me was around the time I purchased an iPod or went to [the Royal Dutch Concert Building].

But now, all has changed.

I found a way to be lazy, not having to purchase or download any songs. This new way, this revolution, is called Last.fm. Some of my friends already had an account for a long time. Typically the real audiophiles were the early users of this system. Ok so what's that last.fm and why is it so great?

Last.fm User Experience

Last.fm is a little web startup from London. A few months ago they probably had a double dozen of employees (now 40). Last.fm is an online audio player that gives you these experiences:

  • generate your own 'radio' by entering artists/categories
  • unlike normal radio you can skip tracks, love tracks or ban tracks
  • while playing, real-time user generated information is displayed in a wiki fashion
  • the company's obsession with statistics allows you to see your musical compatibility with other users
  • when listening to iTunes, last.fm will try to spy on what you listen to mostly
  • The Long Tail, one of last.fm's goals is making all the music in the world available

Basically last.fm and the whole world knows what kind of music you like. For most people this is not a problem, since they really really like showing off what music they like (especially teenagers).

The effects of the Long Tail allows you to explore niches you didn't think existed:

Look I'm the top listener of that dude from Okinawa!

Last.fm Freemium

Last.fm get's the essence of music, they just 'get it'. To quote the first sentence from this research paper on 'Why do Humans Value Music?':

Whenever and wherever humans have existed music has existed also. Since music occurs only when people choose to create and share it, and since they always have done so and no doubt always will, music clearly must have important value for people.

You hear that? Sharing the music!

Like Google, last.fm connects supply with demand. Thanks to their thorough statistical systems, they really know what people like. Last.fm has a Freemium business model that allows you to upgrade your account for 30$/year to get these benefits:

  • listening to the tracks you specified with the 'love' button
  • listening to the tracks of your musical compatible friends
  • listen to your own composed playlists
  • social status (like Flickr-pro)

For now, last.fm doesn't offer real 'select and play'. All tracks played are randomly contained in a radio stream of at least 10 tracks. They do have a little link that allows you to 'buy the cd' (linking you to amazon.com). I assume that in the future we can expected a button that says 'buy and put in my songs'. Of course they depend on the slowly evolving record industry for that.

Maybe these advertisements on their website will speed things up:

Yesterday Last.fm was sold to US' CBS for 280 mln $

female readers: Warning! geek content!

Lately I started realizing that there is a new breed of system administrators. I used to think they just had a boring job maintaining systems and playing BSD snake. But I've come to realize that there are also Agile Sysadmins, the Agmin. These Agmins are constantly adapting systems for performance and scalability. From trying out weird undocumented software to doing mashups with Amazon S3.

At the moment I'm doing a private project that requires a lot of focus on system operations. I am not the best guy for that I have to admit. I can be organized and disciplined, but not in the required maintaining fashion. A skill that is also required by the Agmin. I'm not an agmin (more about this later, because we really need an agmin for this project).

Anyway, I decided to plug out the big ol' Apache server and decided to switch to the ultra-light and fast HTTP server, NginX. The primary argument is obviously performance, second is the philosophy of less is more.

NginX is a light http server coded by some russians. They often use a communist red star in their logo. English documentation is limited, but as a Ruby-ist, I'm used to that. Most of the useful good documentation in the Ruby community comes from blog posts (human conversation and problem solving). OK let's start.

There are a few things that this article will cover:

  • Setting up PHP
  • Wordpress fancy URL rewrites
  • An alternative for mod_userdir
  • Example configuration of php5-fastcgi + rails-userdir hack

First of all, when configuring NginX, you better know regular expressions! (cheat sheet here NginX has a pretty basic configuration syntax (no XML, humans configure it afterall). Things I found particularly useful: rewrite and include).

Setting up PHP

Assuming you have debian, you need the 'php5-cgi' binary (or php4-cgi in case you're slow). We will put this binary in 'fastcgi mode', allowing NginX to execute code on it through sockets:

  #!/bin/bash 
  PHPFCGI="/usr/bin/php5-cgi"
  FCGIPORT="8085"
  FCGIADDR="127.0.0.1"
  PHP_FCGI_CHILDREN=4
  PHP_FCGI_MAX_REQUESTS=1000
  USERID=www-data
  EX=" $PHPFCGI -b $FCGIADDR:$FCGIPORT"
  echo $EX
  nohup env - PHP_FCGI_CHILDREN=$PHP_FCGI_CHILDREN PHP_FCGI_MAX_REQUESTS=$PHP_FCGI_MAX_REQUESTS  USERID=$USERID sh -c "$EX" &> /dev/null &

This script is a modified version of this russian's one. You can call this script phpd ;)

To enable PHP to your vhost/docroot use this:

fastcgi_pass   127.0.0.1:8085;
fastcgi_index  index.php;

fastcgi_param  QUERY_STRING       $query_string;
fastcgi_param  REQUEST_METHOD     $request_method;
fastcgi_param  CONTENT_TYPE       $content_type;
fastcgi_param  CONTENT_LENGTH     $content_length;

fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
fastcgi_param  REQUEST_URI        $request_uri;
fastcgi_param  DOCUMENT_URI       $document_uri;
fastcgi_param  DOCUMENT_ROOT      $document_root;
fastcgi_param  SERVER_PROTOCOL    $server_protocol;

fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
fastcgi_param  SERVER_SOFTWARE    nginx;

fastcgi_param  REMOTE_ADDR        $remote_addr;
fastcgi_param  REMOTE_PORT        $remote_port;
fastcgi_param  SERVER_ADDR        $server_addr;
fastcgi_param  SERVER_PORT        $server_port;
fastcgi_param  SERVER_NAME        $server_name;

# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param  REDIRECT_STATUS    200;

I called it enable_php5, so I can include it in my NginX location directives:

      include        /etc/nginx/enable_php5;

Wordpress Fancy URL rewrites

To enable urls like: http://digigen.nl/2007/05/07/confabiocom-technology-revealed/ you need some special rules. Basically if the file doesn't exist, pass the entire request to wordpress.

/etc/nginx/enable_wordpress:

    # wordpress pretty urls
    # http://drupal.org/node/110224
    location / {
        index index.php;
        if (-f $request_filename) {
            break;  
        }       
        if (-d $request_filename) {
            break;  
        }       
        rewrite ^(.+)$ /index.php?q=$1 last;
    }

An alternative for mod_userdir

In apache you have directory lists by default. I could not find this in NginX so I hacked up a RubyOnRails controller that will handle this:

map.connect 'userdir/:user/:path', :controller => "userdir", :action => 'index', :path => '', :requirements => {:path => /.*/}

Note: users can customize this view by creating ~/www/.home.rhtml or ~/www/.home.css

In your NginX configuration (enable_userdir):

   # enable homedirs
    location ~ /~(.*) {
      rewrite  ^/~(.*)$  /userdir/$1 break;
      include        /etc/nginx/enable_mongrel;
      proxy_pass     http://127.0.0.1:8001;
    }

This is to be added to the Rails routes.rb file. All code for this userdir hack is here. Let me know if/when there is a sane solution for this.

note: AutoIndexModule looks like a sane solution (thanks Drakonen)

Example configuration of php5-fastcgi + rails-userdir hack

server {
    server_name     digigen.nl www.digigen.nl;
    access_log      /var/log/nginx/digigen.nl.access.log;
    index           index.php;
    root            /www/vhosts/digigen.nl;

    include /etc/nginx/enable_userdir;
    include /etc/nginx/enable_wordpress;

    location ~ \.php$ {
      fastcgi_param  SCRIPT_NAME  /www/vhosts/digigen.nl$fastcgi_script_name;
      fastcgi_param  SCRIPT_FILENAME  /www/vhosts/digigen.nl$fastcgi_script_name;
      include        /etc/nginx/enable_php5;
    }
}

I hope this might help some people struggling with the strong taste of Vodka:

 /etc/init.d/apache stop
 /etc/init.d/nginx start # it's ok, the cold war is over

The project is well underway to developing a nice product. Also, as you might see in the below picture, it's kind of fun to use!



Click here to read more and vote for the name

This article is located here, at my joint entrepreneurial blog.

During my scarce free time in the weekends and nights, I will work on some of my web 2.0 projects. A good friend of mine, Aram Versteegen, who’s doing the same thing will join me in blogging the hardships of starting cool web projects.

digigen.nl will be a full-disclosure of our idea’s, technologies and experiences.

Newest articles:

Digigen, Short History and Naked Future

Web Video Conference for the Masses

I ve got a double coupon for that

Digigen blog goes live!

Recently, I’ve been doing some flying and I started noticing something odd. Every time you board or exit an airplane – through the so called aerobridge – you will see only one type of advertisement.

Banking Advertisements

For some reason, every airport you will fly to they’re there. No big consumer advertisements like Coca-Cola, Exxon-Mobil or Fritolay. Only banks.

Flying to Hong Kong, London or Narita will give you HSBC. Flying to Geneva will give you Credit Suisse, Dublin will give you Bank of Ireland and Amsterdam will give you ING.

Now why would the Hong Kong and Shanghai Banking Corporation – which doesn’t have any consumer services in Japan – be interested in advertising to consumers that never heard of HSBC?

Maybe the underlying reason can be found in this piece of corporate statement:

Graham Macnaughton, Country Manager Japan, HSBC Group, commented, “HSBC is proud and honoured to be the first corporate sponsor of airbridges at Narita International Airport, the gateway to one of the world’s most important economic and cultural centers. Next year marks the 140th anniversary since the establishment of HSBC operations in Japan, and we believe the airbridges are symbolic of our unique service offering customers both international reach and local knowledge.”

Ok, so it’s a symbolic thing. Still, isn’t there some secret group of people conspiring?