Skip to content

Instantly share code, notes, and snippets.

@emil-perhinschi
Created November 23, 2018 20:58
Show Gist options
  • Save emil-perhinschi/8d8abed2d3c7e767c2d562a2a83283b5 to your computer and use it in GitHub Desktop.
Save emil-perhinschi/8d8abed2d3c7e767c2d562a2a83283b5 to your computer and use it in GitHub Desktop.
cgi script with plack
<VirtualHost *:80>
ServerName test-cgi
ServerAdmin webmaster@localhost
DocumentRoot /home/www/test_cgi/htdocs
ErrorLog /home/www/test_cgi/logs/error.log
CustomLog /home/www/test_cgi/logs/access.log combined
<IfModule mod_alias.c>
<IfModule mod_cgi.c>
Define ENABLE_USR_LIB_CGI_BIN
</IfModule>
<IfDefine ENABLE_USR_LIB_CGI_BIN>
AddHandler cgi-script .cgi .pl
<Directory "/home/www/test_cgi/htdocs">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Require all granted
</Directory>
</IfDefine>
</IfModule>
</VirtualHost>
#!/usr/bin/env perl
use strict;
use warnings;
use Plack::Request;
my $app = sub {
my $req = Plack::Request->new($_[0]);
my $test = $req->param('test');
[ 200, [ 'Content-Type', 'text/html; charset=UTF-8' ], [ "Hello " . $test ] ];
};
use Plack::Handler::CGI;
Plack::Handler::CGI->new->run($app);
@emil-perhinschi
Copy link
Author

put test.pl in /home/www/test_cgi/htdocs/, make it executable by the web server user, load http://test-cgi/test.pl?test=asdf

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment