View Single Post
  #1   (View Single Post)  
Old 21st March 2016
pmaddams
-Guest-
 
Posts: n/a
Default FCGI.pm on OpenBSD httpd

Hello everyone.

My goal is to use Perl FastCGI with httpd as simply as possible. As I understand it this will require the following steps:

1. get the FCGI perl module with CPAN
2. write a perl script that creates a unix socket in /var/www/run
3. configure httpd to talk to the socket
4. run the script and start the server

One step which I have left out is copying the perl executable and libraries into the chroot. I don't think this should be necessary, since you can chroot within the perl script to "/var/www", chdir to "/", and create the socket in "run". httpd will not be aware of this and simply talk to the socket.

So of course I tried these steps myself before coming here, but did not meet with great success, rather "500 Internal Server Error." This is my story.

First of all I appended httpd_flags="" to /etc/rc.conf.local. Then I did "mv /etc/examples/httpd.conf /etc/httpd.conf". The results of my tweaking were

Code:
server "default" {
        listen on $ext_addr port 80
        root "/"
}
Then I whipped up a quick index.html consisting of <h2>Hello world</h2>. After running "rcctl start httpd" I can type in “localhost” in my browser’s address bar and see “Hello world”. So far so good.

So then I ran cpan as root to get the needed module. perl -V shows that the first entry in @INC is "/home/pmaddams/perl5/lib/perl5/amd64-openbsd". So "install FCGI" put FCGI.pm there.

Now I write a test script "test.fcgi" in /var/www/cgi-bin/ that goes like so:

Code:
#!/usr/bin/perl -T

use strict;
use warnings;

use FCGI;

chroot "/var/www";
chdir "/";

print "done.\n";
Uh-oh. It says "Can't locate FCGI.pm in @INC" and does not show /home/pmaddams anywhere. So I do a quick "mv /home/pmaddams/perl5/lib/perl5/amd64-openbsd/* /usr/local/libdata/perl5/site_perl/amd64-openbsd/" and now it works, printing a nice "done."

Then we get to the gnarly part where lots of things change at once. I altered my perl script according to the instructions at cpan.org. Now it looks like

Code:
#!/usr/bin/perl -T

use strict;
use warnings;

use FCGI;

chroot "/var/www";
chdir "/";

my $in = \*STDIN;
my $out = \*STDOUT;
my $err = \*STDERR;
my $env = \%ENV;

my $socket = FCGI::OpenSocket "run/test.sock", 10;
my $request = FCGI::Request $in, $out, $err, $env, $socket;

while ($request->Accept() >= 0) {
        print "<h2>Hello world</h2>\n";
}
Indeed it has created run/test.sock. So I edit my httpd.conf to look like:

Code:
server "default" {
        listen on $ext_addr port 80
        location “/cgi-bin/*” {
	        fastcgi socket “/run/test.sock”
	        root “/”
        }
}
Then run "test.fcgi & rcctl restart httpd". But I get the 500 error and do not know how to troubleshoot. Please help.

Last edited by pmaddams; 21st March 2016 at 08:20 PM. Reason: link
Reply With Quote