URL Rewrite Using Lighttpd

You will need to enable the mod-rewrite in Lighttpd and then open up the file under /etc/lighttpd/lighttpd.conf

$HTTP["host"] =~ "www.asianeric.com" {
  url.rewrite-final = (

    # Exclude some directories from rewriting
    "^/(wp-admin|wp-includes|wp-content)/(.*)" => "$0",

    # Exclude .php files at root from rewriting
    "^/(.*.php)" => "$0",

    # Handle permalinks and feeds
    "^/(.*)$" => "/index.php/$1"

This configuration should work well with WordPress installation using permalinks.

Migrated from MySQL to SQLite

I bought a new VPS from HostMist a few weeks back and installed Ubuntu with 128M RAM. After running Apache and MySQL for a while, I realised that 128M is simply not enough. So I decided to give Lighttpd and SQLite a try.

Installation is very smooth in Ubuntu for both and configure Lighttpd is easy enough. However, it does take me sometime to figure out how to migrate the data from MySQL to SQLite. I will explain what I did in this post.

Firstly you will need to install a PDO plugin for SQLite to run under WordPress. It should be straightforword enough and no explanations would be needed.

Secondly you will need to migrate your existing data in MySQL into SQlite, unless you just started your new blog. I have found a little shell script to convert exported MySQL schema to SQLite syntax at JBipNet, it is very useful:

if [ "x$1" == "x" ]; then
  echo "Usage: $0 "

cat $1 |
grep -v ' KEY "' |
grep -v ' UNIQUE KEY "' |
grep -v ' PRIMARY KEY ' |
sed '/^SET/d' |
sed 's/ unsigned / /g' |
sed 's/ auto_increment/ primary key autoincrement/g' |
sed 's/ smallint([0-9]*) / integer /g' |
sed 's/ tinyint([0-9]*) / integer /g' |
sed 's/ int([0-9]*) / integer /g' |
sed 's/ character set [^ ]* / /g' |
sed 's/ enum([^)]*) / varchar(255) /g' |
sed 's/ on update [^,]*//g' |
sed 's/\\r\\n/\\n/g' |
sed 's/\\"/"/g' |
perl -e 'local $/;$_=;s/,\n\)/\n\)/gs;print "begin;\n";print;print "commit;\n"' |
perl -pe '
if (/^(INSERT.+?)\(/) {
' > $1.sql
cat $1.sql | sqlite3 $1.db > $1.err
ERRORS=cat $1.err | wc -l
if [ $ERRORS == 0 ]; then
  echo "Conversion completed without error. Output file: $1.db"
  rm $1.sql
  rm $1.err
  echo "There were errors during conversion.  Please review $1.err and $1.sql for details."

I simply copy the code to my local directory named “mysql-sqlite-converter.sh”, dump the MySQL database with:

mysqldump -u {user} -p --compatible=ansi --skip-opt {database} {tablelist} > MyBlog

You will need to make sure that your SQLite database file has the same name as the new dumped MySQL file, in my case is MyBlog.sqlite. Now simply run the script saved before:

sh mysql-sqlite-converter.sh MyBlog

The script will create and overwrite the original MyBlog.sqlite file and you are ready.


URL rewrite support for Lighttpd server

I was setting up WordPress permalinks with Lighttpd but encounter some problems: mod_magnet module was not available for the Lighttpd installed on my VPS. It turned out that I need to install the module manually and then restart the server:

user@server$ sudo apt-get install lighttpd-mod-magnet
user@server$ sudo lighty-enable-mod magnet
user@server$ sudo /etc/init.d/lighttpd force-reload

For the permalink to work I did the following.

Add this piece of code to /etc/lighttpd/lighttpd.conf

$HTTP["host"] == "dev.sudhaker.com" {
    server.document-root = "/sites/sudhaker.com/htdocs"
    magnet.attract-physical-path-to = ( server.document-root + "/rewrite.lua" )

And then

attr = lighty.stat(lighty.env["physical.path"])

if (not attr) then
lighty.env["uri.path"] = "/index.php"
lighty.env["physical.rel-path"] = lighty.env["uri.path"]
lighty.env["physical.path"] = lighty.env["physical.doc-root"] .. lighty.env["physical.rel-path"]

to the rewrite.lua under the server document root directory and it should be up and running.