Scrobble This: last.fm recent tracks AJAX style

So, I’ve been reading up a bit on prototype.js and its Ajax helpers. It’s an amazing tool and helped me write the bit of info at the top of the page. It’s pretty basic, but here’s the code that does most of the work:

function lastfm()
{
    new Ajax.Request('/as/recenttracks.xml',
    {
        method: 'get',
        onLoading: function() {

        },
        onLoaded: function(transport) {
            if (transport.overrideMimeType) {
                transport.overrideMimeType('application/xml');
            }
        },
        onSuccess: function(transport) {
            var response = transport.responseXML.documentElement;
            updateLastfm(response);
        },
        onFailure: failedLastfm()
    });
}

The only issue I ran into was that I was originally using the RSS flavor of recent tracks, however it didn’t split up the artist and track information. It displays it as <title>[artist] – [track]</title>. That en-dash in the middle was preventing me from using title.split() on the JavaScript side of things. Really weird.

Also, since I’m a complete newbie with Ruby, I couldn’t figure out how (read: didn’t take the time to learn) to grab the content from a remote server and serve it up to the JavaScript. I’m sure it’s pretty simple… but I was at work and in a hurry. So, being that I know PHP, I just created a script to download the file and save it to the local disk and setup a cronjob.

Here’s the PHP script:

class lastfm
{
    private $user;
    private $reports;
    private $basews;
    public $saveto;

    function __construct($user)
    {
        $this->user = $user;
        $this->basews = 'http://ws.audioscrobbler.com/1.0/user/';
        $this->reports = array(
            'recenttracks.xml',
            'weeklyartistchart.xml',
            'weeklytrackchart.xml',
            'topartists.xml'
        );
        $this->saveto = '.';
    }

    public function go()
    {
        for ($i = 0; $i < count($this->reports); $i++)
        {
            try
            {
                $opts = array('http' => array('method' => 'GET', 'header' => 'Content-type: text/plain; charset=utf-8'));
                $context = stream_context_create($opts);

                $fp = fopen($this->saveto.DIRECTORY_SEPARATOR.$this->reports[$i], 'w+');
                $stream = fopen($this->basews.$this->user.'/'.$this->reports[$i], 'r', false, $context);
                $string = stream_get_contents($stream);
                fwrite($fp, $string);
                fclose($fp);
                fclose($stream);
                echo 'Saved ' . $this->saveto.DIRECTORY_SEPARATOR.$this->reports[$i] . "\n";
            }
            catch (Exception $e)
            {
                echo $e->getMessage() . "\n";
            }
        }
    }

    public function setSaveto($path)
    {
        if (is_dir($path))
        {
            if (ereg('\/$', $path))
            {
                $path = ereg_replace('\/$', '', $path);
            }
            $this->saveto = $path;
        }
        else
        {
            $this->createDir($path);
            $this->setSaveto($path);
        }
    }

    private function createDir($path)
    {
        if (!is_dir($path))
        {
            $res = `mkdir -p $path`;
        }
    }
}

I’ll hit up the Rails API Docs one of these days and write a simple Ruby script that does all the work of the PHP script. Even better would be to process the XML document using ruby that just returns a string of HTML and use Ajax.PeriodicalUpdater($(e), ...).

Changing Permalinks In Typo

When I switched from WordPress to Typo, I faced the issue of keeping my WordPress permalinks in Typo. Unfortunately, there’s no simple way of doing this. I noticed the ‘redirects’ table in the database, but I could never get it to realy do anything. So, I had to dig in and find the bit of code that controlled the permalinks in Typo.

Typo uses ‘articles’ as it’s base for all posts so I looked in config/routes.rb and found what I needed to change. As you can see from the url of this post, I use ‘content’ as the base of my permalink. So, I changed all the references of ‘articles’ to ‘content’ and all seems to be right in the world.

I changed

1
2
map.connect 'articles',
    :controller => 'articles', :action => 'index'

to

1
2
map.connect 'content',
    :controller => 'articles', :action => 'index'

and then changed

1
2
3
map.connect 'articles/:year/:month/:day',
    :controller => 'articles', :action => 'find_by_date',
    :year => /\d{4}/, :month => /\d{1,2}/, :day => /\d{1,2}/

to

1
2
3
map.connect 'content/:year/:month/:day',
    :controller => 'articles', :action => 'find_by_date',
    :year => /\d{4}/, :month => /\d{1,2}/, :day => /\d{1,2}/

and so on.

The only thing I haven’t gotten to work is to map the pages. I can change the ‘pages’ map, but it doesn’t act as desired. I only had 3 pages in WordPress, so I might as well either alias them or premanent redirect in the Apache configuration.

If anybody has some insight, I’d love to here it. Also, still haven’t figured out why mod_rewrite is working like it should.

Apache2: mod_rewrite vs. mod_proxy

I can’t quite figure this out. I’m trying to write a simple rule to force randys.org to redirect to www.randys.org but it’s not realy working. Of course, I haven’t tried it on a vhost that isn’t proxying request to mongrel. Here’s the rule:

RewriteEngine On
RewriteCond %{HTTP_HOST}    !^www.randys.org$ [NC]
RewriteCond %{HTTP_HOST}    !^$
RewriteRule ^/(.*)          http://www.randys.org/$1 [R=301,L]

Anyone?

Typo, Apache & Mongrel, Oh My!

Wow. I’ve been testing the possibility of running Typo on my VPS with the pre-notion that it just wouldn’t work very well. I think I may be wrong. It’s been running for about a week while I tweak some shit and so far, my memory performance has been stable. Of course, thing would probably be different if I threw some real traffic at it… but, then again, I don’t get a lot of that.

The Setup

Initially, I was going to use lighty + fastcgi to serve up the Rails application. So, I had setup lighty to serve up my PHP/MySQl sites and that worked just fine. Then I started reading up on Mongrel and wanted to see what all the hubub was about. But then I got to reading the Mongrel site (more specifically the part where he says don’t use lighty and mod_proxy).

Crap.

Aight, so back to Apache and their proxy setup. no biggie. I racked my brain for several hours one night trying to figure out why the hell I kept getting these 403 Forbidden errors in Apache. Hours. After the millionth Google search, I finally found the issue: The mod_proxy configuration in Ubuntu is turned off by default (well, not really turned off… it just denies traffic to the proxy server).

 8     <Proxy *>
 9         Order deny,allow
10         #Deny from all
11         Allow from .randys.org
12     </Proxy>

Line 8 was initially not commented out. I had to comment that out and add the Allow from .randys.org bit.

Once I got that changed and reloaded Apache, everything is working nicely together.. even PHP.

The Tweaks

So far, the only tweaks I’ve managed to make is to the flickr Sidebar plugin. It now uses Lightbox V2. That was a bit tricky, considering I don’t really know Ruby but, it all worked out in the end.

As I figure out more stuff to do, I’ll post more.

Ubuntu + Rails + Typo

So, I’ve decided to give Typo another shot. This time, using Apache 2.0 and Mongrel running on Ubuntu. So far, it seems kind of sluggish. I could just be the VPS node that I’m on. I’m well within my memory limits (currently at ~63% capacity), but VPSLink has been experiencing a rather high level of disk I/O issues that’s causing a slow down in overall performance of my VPS.

Anyway, Typo is definitely more pleasing to look at (from an administration standpoint) and it will force me to learn the ins and outs of Ruby on Rails.

Gentoo On a 256MB VPS != Fun

So, I’ve switched form Gentoo to Ubuntu. It got to the point where I
couldn’t compile anything. Mostly due to the lousy disk performance of
my awesome new host. My first venture was Debian, but, I found it difficult to install newer packages (PHP5, Ruby, etc). I like Debian so Ubuntu was a natural second choice and they have the packages I need without having to futz with too many things.

New Deals

So, while re-configuring the web server (I’ve gone with Apache this time… more on that later) and re-installing WP, I found a couple of cool plugins. One is myGallery. It’s fancy. Have a look at the Photos section if your so inclined.

Another thing I’ve been working on is an AJAX recent track list for last.fm. It can be seen up top. Should work in Firefox, Safari and IE7 (I haven’t tested it in IE6… but hopefully it should work). Maybe in the coming days I’ll share the code… if your interested.

That’s all.

IE 7 Hates USB Mice

I’ve half assedly (yes, it’s a word, I made it up) followed the IE 7 development. I’m a web developer, it’s my job to be aware of such things. So, when it was still in beta (about 2 or 3 months ago) I installed it at work to see what it was all about. First impression: bloated piece of crap that does the exact same shit that Firefox has been doing for years; tabs, RSS, popup blocking, add on’s (extensions for the < 2.0 users), et al. The interface was horrible (still is) and it just wasn’t that interesting to me. It had a distinct Vista feel for XP and we already know how I feel about Vista.

So when the release of IE 7 was final earlier this week, I thought, “well, maybe the polished version is better.” Well, it wasn’t. Still the same bloated piece of crap I installed a few months ago. Not only that, but one of the first things that left a really bad taste in my mouth was the “Windows Genuine Advantage” bullshit during the install. This has to be the worst move Microsoft could have made. Not only is it annoying (not that it took a long time to verify that the version of Windows I was using was authentic), but it’s extremely insulting.

“We don’t trust you as far as we can throw you, so, we’re going to need to check your license to make sure it’s legit. Hope you don’t mind.”

Horse shit. If they want to check the license against a database of known compromised keys, so be it. Do so unbeknownst to the user. Don’t tell them about it. If it’s an unauthentic key, notify them and let them know how to purchase a valid license. It’s extremely rude.

The second thing I did was to open IE 7 and create a new tab. “Woohoo,” I thought, “IE has tabs.” One second later, the application completely vanished. Yes, vanished. No crash reporter deal; no popup telling me everything is cool (which it’s not), the application just crashed. Nothing. I could reproduce this every time. Open IE, create a new tab, POOF!

So, I set out to figure this out. Why the hell is this damn thing crashing every time? Honestly, I normally would have just uninstalled the damn thing and went about my merry business. However, I learned from our Help Desk at work that they are forcing the update on everyone’s workstation. Why, couldn’t tell you. The application was out for a day and the ever so helpful Help Desk was walking around installing IE 7 for everyone.

I spent half the day searching for answers and re-installing the software with no luck. The shit just wouldn’t work. Typical. At some point, I told one of my colleges about the problem I was having. I had already started with the add-on’s turned off and disabled a bunch on them that I didn’t need. He asked me if I was using a USB mouse.

“Yes, why?”

“Try using the USB to PS/2 adapter. Joey [the ever so helpful Help Desk guy] said to use it when I was having issues one time.”

Are you shitting me? “OK”, I thought, “nothing else seems to be working and I guess one more reboot wouldn’t hurt.” So, I shut down the machine, unplugged my USB mouse and plugged it into the PS/2 port. Mind you, this is a Microsoft mouse running Microsoft drivers. Well, when I rebooted, fired up IE and created a new tab, guess what; no crash.

So here’s my question, Microsoft: Why the hell does your mouse cause your software to disintegrate into thin air?

In the end, I’m trying IE 7 out for a day or two to see how it behaves. So far, I’m unimpressed. Like I said before; it does the same thing Firefox has been doing for years. It seems that the best Microsoft could muster up in the past, what, 3 years, is to play catchup with the rest of the internet world.

Way to go Microshit! You just earned a C- in the school of web development.

Technorati Tags: ,

LiMP: Lighttpd, MySQL & PHP on OS X

In following with the LAMP, MAMP, and WAMP themes, I’ve come up with my own acronym: LiMP. Lighttpd, MySQL, PHP. Of course, this doesn’t really follow the conventions of the other acronyms (my OS isn’t represented). Mainly because adding an ‘M’ just doesn’t sound (or look) right. It’s a great setup and I recently reconfigured it so it’s a (somewhat) isolated installation that could potentially be installed on any OS X system. I also managed to get ExecWrap working properly as well.

*NB*
This is a fairly technical article and requires getting your fingers dirty in the Terminal (a.k.a. comman line). If you’re not fully comfortable in the Terminal, I suggest you familiarize yourself with the Terminal. You’ll also need to have installed the latest version of Xcode.

You can build this just about anywhere on your system you like. I personally keep everything in

/usr/local/src

but you can build this anywhere you want on your system. I also like to

sudo -s

so that I’m always root when comiling and installing these things. Let’s jump in…

Create your src directories:

mkdir -p /usr/local/src && cd /usr/local/src

That’s it. Now lets dig in…

Setting up Lighttpd on OS X

I figured building this on OS X wouldn’t take too much effort and I was pretty much right. Lighttpd builds just fine on OS X but it does need some other libraries installed for certain functionality. Specifically, fastcgi and Perl Compatible Regular Expressions. These libraries install without issue as well.

First lets grab the fastcgi libraries:

curl -O http://www.fastcgi.com/dist/fcgi-2.4.0.tar.gz
tar zxvf fcgi-2.4.0.tar.gz && cd fcgi-2.4.0
./configure
make
make install
cd ..

Now lets get the PCRE libraries:

curl -O ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-5.0.tar.gz
tar zxvf pcre-5.0.tar.gz && cd pcre-5.0
./configure
make
make install
cd ..

Now for lighttpd:

curl -O http://www.lighttpd.net/download/lighttpd-1.4.12.tar.gz
tar zxvf lighttpd-1.4.12.tar.gz && cd lighttpd-1.4.12
./configure --prefix=/Library/limp/lighttpd

Hopefully, you’ll see something like this after the configure script is done.

Plugins:

mod_rewrite     : enabled
mod_redirect    : enabled
mod_ssi         : enabled
mod_cgi         : enabled
mod_fastcgi     : enabled
mod_proxy       : enabled
mod_evhost      : enabled
mod_simple_vhost: enabled
mod_mysql_vhost : enabled
mod_access      : enabled
mod_alias       : enabled
mod_setenv      : enabled
mod_usertrack   : enabled
mod_compress    : enabled
mod_auth        : enabled
mod_status      : enabled
mod_accesslog   : enabled
mod_rrdtool     : enabled
mod_secdownload : enabled
mod_expire      : enabled

If you don’t see mod_fastcgi in there, something went south.

make
make install
cp doc/lighttpd.conf /Library/limp/lighttpd/lighttpd.conf

MySQL

For MySQL, I just used the standard binary installation provided by MySQL. Therefore, we’ll need to also configure and install the libraries after installing the binary package. (Thanks to Richard Valk for his article series for this bit).

First, download and install MySQL (version 5.0.24a as of this writing) Standard binary for OS X for your platform (PPC or Intel). Once you’ve installed the package, install the StartupItem and make your life simple-er (??). After everything is setup, you should modify your

PATH

environment variable again in your ~/.bashrc file.

export PATH="/usr/local/bin:/usr/local/mysql/bin:"${PATH}

Now we have to rebuild mysql and install the shared libraries we need for building PHP. Make sure you’re still in your ‘src’ directory.

curl -O http://www.stathy.com/mysql/Downloads/MySQL-5.0/mysql-5.0.24.tar.gz
tar zxvf mysql-5.0.24.tar.gz && cd mysql-5.0.24
./configure --prefix=/usr/local/mysql \
 --localstatedir=/usr/local/mysql/data \
 --libexecdir=/usr/local/mysql/bin \
 --libdir=/usr/local/mysql/lib \
 --with-server-suffix=-standard \
 --enable-thread-safe-client \
 --enable-local-infile \
 --enable-shared \
 --with-zlib-dir=bundled \
 --with-big-tables \
 --with-readline \
 --with-archive-storage-engine \
 --with-innodb \
 --without-docs \
 --without-bench \
make
make install
cd ..

Compiling PHP on OS X (with the mysqli extension)

This was fairly straight forward with the exception of GD. It took me a while to figure this out, but I was using

--with-gd=/sw

and this was confusing the compiler for some reason. When I changed it to just

--with-gd

everything compiled fine… including the mysqli extension. Here’s what my config looks like:

./configure \
 --prefix=/Lbrary/limp/php \
 --enable-fastcgi \
 --enable-force-cgi-redirect \
 --enable-mbstring \
 --with-xml \
 --with-zlib \
 --with-curl \
 --with-mysql=/usr/local/mysql \
 --with-pdo-mysql=/usr/local/mysql \
 --with-mysqli=/usr/local/mysql/bin/mysql_config \
 --with-pdo-sqlite \
 --with-sqlite \
 --with-mcrypt=/sw \
 --with-gd \
 --with-jpeg-dir=/sw \
 --with-png-dir=/sw \
 --with-zlib-dir=/sw \
 --with-xpm-dir=/usr \
 --enable-exif \
 --enable-ftp \
 --enable-libxml \
 --enable-soap \
 --enable-sockets

make && make install
cp /Library/limp/php/bin/php /Library/limp/php/bin/php-cgi

I’m renaming the php binary to php-cgi because, well, that’s what it is. It’s the CGI version, not the CLI version. If you want to compile the CLI version, replace

 --enable-fastcgi \
 --enable-force-cgi-redirect \

with

 --enable-cli \

and run

make && make install

again. Only do this after you’ve renamed the php file to php-cgi. Otherwise, you’ll overwrite the cgi version with the cli version and it won’t work with fastcgi.

Building ExecWrap


I’ll have to finish this at a later date… sorry. This was originally posted to my old WordPress blog as a Draft but got imported into Typo via the wordpress2.rb script as a published article… so I left it.

Thank God for Akismet

I must say, over the couple of years, I’ve been dealing with spam on daily basis. Not only email spam, but comment spam as well. And it’s gotten much much worse over the past year. Dreamhost (my former hosting provider) tried to implement SpamAssassin but it didn’t really work that well. I was still receiving around 5 emails a day that didn’t get caught. I also tried using procmail to process email as it came in, but trying to catch spam at that lever is far to tedious.

I’ve sinve moved my mail over to Google Hosted (which has apparently change to Apps for your Domain). Google’s spam catching has been pretty good thus far with less than 2 emails per day slipping through (it’s actually more than that, but I’m not counting my gmail address that gets delivered to my .org address).

So, what IS this Akismet, anyway?

Akismet is a plugin for WordPress that acts much like SpamAssassin in that it filters throug the content of a particular comment and holds it for either approval or (in almost all cases) deletion. Akismet has been 100% for me. There have been absolutely no* false positives (spam that’s not really spam). Since I’ve installed the plugin (probably about a year ago), it’s caught *2,166 spam. Hurray for Akismet… thanks!

The way it works is similar to the way RBL checks work for email spam. Each time a comment is submitted, it is sent to the Akismet web service. Akismet then runs a bunch of tests on the comment and “returns a thumbs up or thumbs down.” You have to provide an API Key much like you would with other popular public APIs, but you can get one of those for free (as long as you’re not “making ‘mad paper’” from your site) from the Akismet website.

So, i just wanted to express my dislike for spam and that between Google and Akismet, I rarely have to deal with it. Thanks!

Howto Setup a Virtual Mail Server with Postfix/Postgrey, Courier IMAP and MySQL

I haven’t written this yet, but I should have some good stuff here on how you can set up a mail server using the above. My setup works pretty well at the moment and Greylisting seem to take care of 99% of the spam. Actually, I only have like 3 email accounts setup on the server at the moment and most of the email addresses are relatively new. However, I do see a lot of potential spam hit my SMTP server trying to relay to my .org account (even though my MX record is pointing to Google).

So stay tuned…

How-To: Lighttpd, ExecWrap, PHP, WordPress & Gallery2 On A Gentoo VPS

Part of my [decision to change hosting providers][1] was to expand my knowledge of technologies. I know how to write PHP, SQL and a whole host of other languages. What I was less familiar with was the servers that run them and other parts of a hosting system (mail, dns et al). Switching to a VPS setup allowed me to explore my options in what I would run on my system and fine tune the processes to run under limited resources.

[1]:http://www.randys.org/2006/08/21/so-long-dreamhost-ill-miss-you/

I was already familiar with [Apapche][2] and how to set that up with PHP. Apache2 makes it really easy to setup suExec with mod_suphp. Simply add “SuPHP_UserGroup $user $group” to a virtual host and viola, all PHP processes run as that user (as fastcgi). That was great and all, but on a system with limited resources, apache is dog. It sucks up way too much memory. After setting up my VPS and running all the services, I was up to about 150MB of RAM used. That’s with apache2, php, mysqld, postfix, postgrey, courier-imapd (and ssl), courier-pop3d (and ssl) and mailman (which is another memory hog, but that’s another post) running. Granted 150MB isn’t that bad for a web server, especially if you have an entire system to yourself that has 1 or 2 GB of RAM. I’m on a [VPS with a mere 256MB][3] of RAM.

[2]:http://httpd.apache.org/
[3]:http://www.vpslink.com/gentoo-vps/

##Enter Lighty##

[Lighttpd][4] is an open source, fast and efficient alternative to Apache. It pretty much does everything Apache does but with a much smaller footprint. Yes, it was a little more difficult to setup, but most of my troubles came from not knowing the Lighty configuration syntax. It’s not hard to master, just different than Apaches familiar tag based config files.

[4]:http://www.lighttpd.net

So far, this is what I have running on my VPS:

lighttpd (1.4.11)
php* (5.1.4) (+fastcgi)
mysql (4.1.21)
postfix (2.2.10)
postgrey (1.24)
courier (4.0.4)
openssh (4.3_p2)
tinydns (1.05)
proftpd (1.2.10)

Current memory usage:

Total: 239 MB Used: 96 MB Free: 143 MB

**UPDATE**: I recently added a [Typo][5] blog ([RoR][6] application) to one of the domains I’m hosting and my memory usage jumped a little… well, a lot really. I’m probably sitting at about 120-130 MB used at the moment.

[5]:http://typosphere.org/
[6]:http://www.rubyonrails.org

##And now the HOWTO##

Configuring lighty wasn’t that hard. The hardest part was figuring out things like setting up rewrite rules for web applications like [Wordpress][7] and [Gallery2][8] [search engine friendly URLs][9]. The other tricky part was getting ExecWrap (similar to Apache’s suExec wrapper) working properly. Well, it wasn’t that tricky, I just had some settings wrong so it _appeard_ to be tricky. Let’s tackle the ExecWrap part first.

[7]:http://www.wordpress.org
[8]:http://gallery.menalto.com/
[9]:http://www.randys.org/content/2004/07/26/google-friendly-urls-with-php-and-apache/

####ExecWrap Your PHP####

You’ll need to [grab, build and install the ExecWrap][10] wrapper first. It’s actually pretty straight forward. The important part is setting the correct permissions on the files involved in this setup (and using the correct UIDs and GIDs for the wrapper). For the sake of this post, I’ll skip that part. If I get enough questions about it, I’ll post a follow up on how to set this up properly.

[10]:http://cyanite.org/execwrap/

So, here’s my setting for PHP/FastCGI setup on lighty:

fastcgi.server = (
“.php” => ((
# socket – this needs to be writable by the webserver itself
“socket” => “/var/run/fastcgi/fastphp.socket”,
# bin-path – the path to the execwrap script — see NB below
“bin-path” => “/usr/lib/php5/bin/execwrap”,
# check-local – Not 100%, but I’m pretty sure this
# disables cheking that the local file exists
“check-local” => “disable”,
# max-procs – Maximum number of procs to fire up.
# I’m pretty stingey here, but my site doesn’t see
# a lot of traffic.
“max-procs” => 1,
# bin-environment
“bin-environment” => (
# Howman PHP_CFGI_CHILDREN to start up
“PHP_FCGI_CHILDREN” => “4″,
# Maximum request (per child? i dunno)
“PHP_FCGI_MAX_REQUESTS” => “1000″,
# UID – User ID you want the script to execute as
“UID” => “1000″,
# GID – Group ID you the script to execute as
“GID” => “1000″,
# TARGET – the actual script to run
“TARGET” => “/usr/lib/php5/bin/randy.php.sh”,
# CHECK_GID – this just checks the GID of the wrapper script
“CHECK_GID” => “1″
),
# Copied from another site… not quite sure what it
# does other than copying those env to $_ENV
“bin-copy-environment” => (“PATH”, “SHELL”, “USER”),
# Fixes broken $_SERVER['PATH_INFO] I believe
“broken-scriptfilename” => “enable”
)
)
)

The contents of _randy.php.sh_:

#!/bin/sh
exec /usr/lib/php5/bin/php-cgi

**NB**: Note that the execwrap script must be executable by lighty and must also have the SUID bit set. Also, the shell script needs to be owned by the user in which you wish to execute PHP as (in my case, my username). Also note that execwrap can live anywhere you specify **when you compiled the script**. In my case, I specified in the execwrap_config.h _/usr/lib/php5/bin_ as the path where it will live. The shell script must also live under the same path.

###Wordpress & Gallery URLs###

Permalinks. The best thing since sliced bread. The applications work flawlessly with Apache (if you can use .htaccess in your setup) but take a little tweaking in lighttpd.

####Wordpress####

I futzed around with this for several hours trying to get this to work properly. Trying to get my head around regular expressions and all the different possible links used in WordPress. And it all came back to to a really simple lighttpd setting (which oddly enough, doesn’t involve rewite at all).

server.error-handler-404 = “/content/index.php?error=404″

That’s it. That and make sure your permalinks setting doesn’t contain the /index.php/.

**Update**: The above solution to WordPress’ permalinks might not be the best. The fact that it’s using the 404 handler might send a 404 response back to the browser. The other issue to worry about is whether or not this is sending a temporary redirect (301). If you have content indexed by a search engine, this will ruin your page ranking. _2008-06-06_

####Gallery2####

Gallery was a bit more difficult. Well, not really. I ended up doing a little R&D (i.e. Rob & Duplicate) [from the gallery2 codex][11].

[11]:http://codex.gallery2.org/index.php/Gallery2:Lighttpd_URL_Rewrite

url.rewrite = (
“^/(.*)/Rewrite.txt$” => “/$1/Works.txt”,
“^/gallery/v/(\?.+|\ .)?$” => “/gallery/main.php?g2_view=core.ShowItem”,
“^/gallery/admin[/?]*(.*)$” => “/gallery/main.php?g2_view=core.SiteAdmin&$1″,
“^/gallery/d/([0-9]+)-([0-9]+)/([^\/]+)(\?|\ )?(.*)$” =>
“/gallery/main.php?g2_view=core.DownloadItem&g2_itemId=$1&g2_serialNumber=$2&$3″,
“^/gallery/v/([^?]+)/slideshow.html” =>
“/gallery/main.php?g2_view=slideshow.Slideshow&g2_path=$1″,
“^/gallery/v/([^?]+)(\?|\ )?(.*)$” =>
“/gallery/main.php?g2_view=core.ShowItem&g2_path=$1&$3″,
“^/gallery/c/add/([0-9]+).html” =>
“/gallery/main.php?g2_view=comment.AddComment&g2_itemId=$1″,
“^/gallery/c/view/([0-9]+).html” =>
“/gallery/main.php?g2_view=comment.ShowAllComments&g2_itemId=$1″,
“^/gallery/p/(.+)” =>
“/gallery/main.php?g2_controller=permalinks.Redirect&g2_filename=$1″
)

Make sure you change out the `^/gallery/` parts to where you have Gallery2 installed.

##Happy Little VPS##

All in all, the VPS is running really smoothly. I have everything I had (thechnology wise) at [Dreamhost][12] but with twice the performance. My site is defintely faster on the VPS than it was on Dreamhost.

[12]:http://www.dreamhost.com/r.cgi?24650

Stay tuned for more HOWTOs on setting up these things on a Gentoo Arch Linux VPS. I plan on writing something for a Postfix/Courier virtual domain setup at some point. If you find this useful, pass it along. I’d be real interested in seeing how this server performs under a heavy load. Perhaps you [Digg][13] it?

[13]:http://digg.com/linux_unix/Lighttpd_ExecWrap_PHP_Wordpress_Gallery2_On_A_Gentoo_VPS