Home Blog CV Projects Patterns Notes Book Colophon Search

PostgresSQL from Apache Lua

28 Oct, 2021

Continuing the theme of using databases from Lua embedded in Apache, I've also had a go at accessing PostgreSQL.

Caution: After these changes I personally decided I was too far down the rabbit hole. I didn't fancy maintaining all the security patches for Apache and re-building each time. So I don't use or recommend this approach. Hopefully it is interesting though!

Caution: Also, this post is written from notes I made when I tested that this patch fixes the problem at the time, and although I've tested the .deb file builds with these written up instructions, I haven't tested installing the resulting package again to check the PostgreSQL connectivity works with these exact instructions.

This isn't quite as straightforward as you'd think on Debian stable because of this bug:

https://bz.apache.org/bugzilla/show_bug.cgi?id=56379

If you install Apache from the backports repo, I think this problem goes away (haven't tested it). But if you want to fix it yourself, read on.

Luckily, if you follow the patch attached in that ticket and rebuild apache, all is well.

First, set up the chroot as described in Rebuilding libsqlite3-mod-spatialite in a chroot for Apache Lua like this:

sudo apt install -y binutils debootstrap
mkdir -p /tmp/chroot/buster
mkdir -p /tmp/chroot/cache
sudo debootstrap --keyring=/usr/share/keyrings/raspbian-archive-keyring.gpg --cache-dir=/tmp/chroot/cache buster 
 /tmp/chroot/buster http://raspbian.raspberrypi.org/raspbian/
sudo chroot /tmp/chroot/buster

cat << EOF > /etc/apt/sources.list.d/source.list
deb-src http://raspbian.raspberrypi.org/raspbian/ buster main contrib non-free rpi
EOF

apt update
apt install -y dpkg-dev
apt install -y locales
dpkg-reconfigure locales

Now within the chroot, follow these instructions.

First you need to find your apache version.

If you have followed Apache mod_md on Debian and are using Apache from backports you'll need to set up the backports repos in the chroot too the same way you did before.

Whichever version of Apache you want to build for, start by setting APACHEVER (apache2 -v will tell you the version if you aren't sure).

# Get the source code
export APACHEVER='2.4.38'

Now apply the patch:

cd /tmp/
apt-get source -y apache2="$APACHEVER"
cd "apache2-$APACHEVER/modules/lua"
cp lua_dbd.c lua_dbd.c_original
apt install -y curl
curl https://bz.apache.org/bugzilla/attachment.cgi?id=31502 > lua_dbd.c.patch
patch -p0 < lua_dbd.c.patch
cd ../../

apt build-dep -y libaprutil1-dbd-sqlite3
dpkg-buildpackage -b

Finally exit the chroot:

exit

You can now install the .deb files from /tmp/chroot/buster/tmp/.

Then restart Apache:

sudo service apache2 restart

Comments

Be the first to comment.

Add Comment





Copyright James Gardner 1996-2020 All Rights Reserved. Admin.