|
OpenBSD General Other questions regarding OpenBSD which do not fit in any of the categories below. |
|
Thread Tools | Display Modes |
|
|||
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 "/" } 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"; 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"; } Code:
server "default" { listen on $ext_addr port 80 location “/cgi-bin/*” { fastcgi socket “/run/test.sock” root “/” } } Last edited by pmaddams; 21st March 2016 at 08:20 PM. Reason: link |
|
||||
You may want to use slowcgi(8) as your FastCGI <-> CGI interface, as discussed in this misc@ thread.
http://marc.info/?t=141665013300001&r=1&w=2 |
|
|||
Dudebro! It's working. I read the man page for slowcgi and it gave me an essential hint: the socket that httpd communicates with has to be owned by www:www.
Making this change got rid of the 500 error. My quick hack was to just chown the socket after starting the Perl process. However, I was still looking at a blank screen, so I then changed the script to include the line Code:
print "Content-Type: text/html\n\n"; |
|
||||
Replying to myself here, but I gave it another go and figured it out. The perl script needs to be started from the command line first, then it works as advertised by the OP. I've tested it by converting a few of my cgi scripts to use the FCGI method.
This is pretty neat. Now I just need to turn FCGI into an OpenBSD package for cleaner installation. |
Tags |
cpan, fastcgi, httpd, openbsd, perl |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Install OpenBSD httpd on FreeBSD? | notooth | FreeBSD Ports and Packages | 5 | 3rd November 2019 06:03 PM |
Patch for OpenBSD 5.6 httpd(8) | J65nko | OpenBSD General | 12 | 7th January 2015 12:49 PM |
httpd in OpenBSD 5.6 | jorisvh | OpenBSD Packages and Ports | 8 | 4th November 2014 12:14 AM |
is nginx going to be default OpenBSD httpd? | ershiba | OpenBSD General | 4 | 6th January 2013 03:55 AM |
Problems getting lighttpd working with php and fcgi | pormogo | FreeBSD Ports and Packages | 3 | 6th June 2008 10:02 PM |