discord.jse.io" itemprop="description"/>

Jonah's Blog

Jonah's blog is here

TL;DR: If you just want the rewrite rules for Lighttpd, scroll to the bottom code snippet.

So like most every other PHP app I've worked with, everybody seems to support both apache and nginx but poor old lighttpd gets left out in the cold and has no support on how to configure it in documentation.

Well have no fear, because you'll have to pry lighttpd out of my cold dead hands!

A while back I setup a VHOST for jseb.ca on Lighttpd with an FTP server so I could integrate it with Sharex. One other feature sharex seems to support is "short URLs" using an API from a PHP script called YOURLS. So I wanted to install it on my low end box.

Now if you caught on earlier, this blog is hosted using a flat-file database platform called htmly, because my lowendbox with only 128MB RAM isn't really ideal for running something like wordpress. MySQL can sure eat the RAM, so I sort of decided to not use MySQL on this server at all.

SQLite on the other hand is a perfect candidate. While it locks the entire database when you're writing to it, something like a URL shortener is a perfect application, since it's pretty much read only. Only time it writes is when I decide to add a URL, which is a fast query and so few and far between, it's a way better candidate for a personal URL shortener over MySQL for a site my size anyway.

Unfortunately, YOURLS doesn't support SQLite out of the box. Luckily there's a great project here on github that adds it. Sweet! That was easy! Install php5-sqlite on my Debian install, chown/chmod your stuff so PHP can write to the directory YOURLS is in, install it by going to /admin/ and we're all set.

However, first thing you'll notice if you're running lighttpd is you'll get 404s since lighttpd doesn't support .htaccess, which YOURLS generates when you first install it. A search around on the internet will find stuff like this, but all the snippets in the examples causes issues for me.

While the last post from gsdefender (from Apr 24, 2016) works, my index.html on jseb.ca doesn't! Now I know it's not special, but it triggered me that if you visit the root, rather than showing my index.html it resulted in a redirect loop which freaked out Chrome.

Now like you probably figured out by now if you read anything here, I'm not much of a sysadmin or programmer, but I know my way around enough to be dangerous. I never got my head around regex stuff, but a quick look at lighttpd documentation says the ?

match zero or one of the previous symbol

Previous being keyword here... I just removed it.

So, now, with a vhost setup and mod_rewrite enabled for lighttpd, my lighttpd.conf looks like this for jseb.ca:

$HTTP["host"] == "jseb.ca" {
    server.document-root = "/var/www/upload/"
    url.rewrite-once = (
#        "^/([0-9A-Za-z-]+)?$" => "/yourls-go.php?id=$1",
#        "^/([0-9A-Za-z-]+)?\+$" => "/yourls-infos.php?id=$1",

        "^/([0-9A-Za-z-]+)$" => "/yourls-go.php?id=$1",
        "([0-9A-Za-z-]+)\+$" => "/yourls-infos.php?id=$1",
)

As you can see, the original copy-pasta from the github issue is commented out so you can note the difference between the two. It works for me... now my uploads and shorturls both reside on jseb.ca and coexists pefectly along with an index.html. So hopefully this helps anybody else who wants to run YOURLS on lighttpd.

Why did they put the ? to begin with? I don't know? Perhaps you can tell me? enter image description here