Perl

In /etc/httpd.conf:

server "example.ircnow.org" {
        listen on * port 8080
        root "/htdocs/perl"
        location "*.pl" {  
                fastcgi
        }
        location "/.well-known/acme-challenge/*" {
                root "/acme"
                request strip 2
        }
}

To figure out what files need to be copied into the chroot:

$ ldd /usr/bin/perl /usr/bin/perl:

        Start            End              Type  Open Ref GrpRef Name
        0000022622dc8000 0000022622dcd000 exe   1    0   0      /usr/bin/perl
        000002285bdc7000 000002285c133000 rlib  0    1   0      /usr/lib/libperl.so.20.0
        00000228c7de6000 00000228c7e16000 rlib  0    2   0      /usr/lib/libm.so.10.1
        000002282f00d000 000002282f101000 rlib  0    2   0      /usr/lib/libc.so.96.0
        0000022914fb2000 0000022914fb2000 ld.so 0    1   0      /usr/libexec/ld.so

So I start with this initial guess to build the chroot. I run the following as root:

mkdir -p /var/www/usr/bin/
mkdir -p /var/www/usr/lib/
mkdir -p /var/www/usr/libexec/
cp /usr/bin/perl /var/www/usr/bin/
cp /usr/lib/libperl.so.20.0 /var/www/usr/lib/
cp /usr/lib/libm.so.10.1 /var/www/usr/lib/
cp /usr/lib/libc.so.96.0 /var/www/usr/lib/
cp /usr/libexec/ld.so /var/www/usr/libexec/

We need to turn on slowcgi:

$ doas rcctl enable slowcgi
$ doas rcctl start slowcgi

Then we run:

$ doas chroot -u www -g daemon /var/www perl

I test some random gibberish to make sure perl works inside the chroot:

print "shibboleth";

Then ctrl+d to escape; and since it echoes shibboleth, it works.

Now I put an index.pl in /var/www/htdocs/perl/ just to see if the web server loads it:

#!/usr/bin/perl -w
use strict;
print "Content-Type:text/html\n\n";
print "This is the index file for perl.oddprotocol.cf\n";

Make sure to set the proper permissions:

$ doas chown -R www:daemon /var/www/htdocs/perl/
$ doas chmod +x /var/www/htdocs/perl/index.pl

At this point I try running this command:

$ curl example.ircnow.org:8080/index.pl

I get a 500 Internal Error, which means perl is not able to execute properly.

So I search for missing perl libraries:

$ doas find / -iname '*perl*'

The interesting one is the folder /usr/libdata/perl5 . We definitely need these libraries, so I update my script for creating the chroot:

mkdir -p /var/www/usr/bin/
mkdir -p /var/www/usr/lib/
mkdir -p /var/www/usr/libexec/
mkdir -p /var/www/usr/libdata/
cp /usr/bin/perl /var/www/usr/bin/
cp /usr/lib/libperl.so.20.0 /var/www/usr/lib/
cp /usr/lib/libm.so.10.1 /var/www/usr/lib/
cp /usr/lib/libc.so.96.0 /var/www/usr/lib/
cp /usr/libexec/ld.so /var/www/usr/libexec/
cp -R /usr/libdata/perl5 /var/www/usr/libdata/