perl - Setting up mod_perl on OSX Lion Apache server -
i new both perl , apache servers. i'm trying basic hello world going cgi script. here code hello world cgi file:
#!/usr/bin/perl print "content-type: text/html\n\n"; print "<h1>hello world</h1>\n";
when execute cgi script on command line, ./hello.cgi, works, when open hello.cgi in browser, displays text of cgi file.
when @ error_log in /var/log/apache2/error_log can see mod_perl running:
apache/2.2.21 (unix) dav/2 mod_perl/2.0.5 perl/v5.12.3 configured -- resuming normal operations
but when run following perl program, appears don't have "mod_perl" env variable:
if (exists $env{"mod_perl"}) { print "yay!\n"; } else{ print"mod_perl not working\n"; }
by way, hello.cgi file , perl script above located in /users/myusername/sites/
could me configure mod_perl can view hello.cgi in browser? i've been reading mod_perl documentation , searching forums many, many hours no avail. in advance
@sebastianstumpf got first example work, still can't seem mod_perl script going. i've been reading through documentation, haven't been able figure out. help, way. i'm grateful
update: believe got working! help!
if using stock apache/perl of mac os x lion and don't need mod_perl don't have configure anything. create file .cgi extension in /library/webserver/cgi-executables
, adjust permissions via sudo chmod 755 file.cgi
. script executed via cgi (not mod_perl). tried , worked fine:
$ sudo -s # cat - > /library/webserver/cgi-executables/test.cgi #!/usr/bin/perl use strict; use warnings; use cgi qw/:standard/; use data::dumper; print header, start_html, h1('works'), end_html; ^d # sudo chmod 755 /library/webserver/cgi-executables/test.cgi # exit
testing it:
$ curl -i http://localhost/cgi-bin/test.cgi http/1.1 200 ok date: mon, 11 jun 2012 22:29:24 gmt server: apache/2.2.21 (unix) dav/2 transfer-encoding: chunked content-type: text/html; charset=iso-8859-1 <!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en-us" xml:lang="en-us"> <head> <title>untitled document</title> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> </head> <body> <h1>works</h1> </body> </html>
if need mod_perl, have @ documentation. configuration part of introduction should need mod_perl running.
edit:
i've added following lines /etc/apache2/httpd.conf
, restarted web server , mod_perl works:
loadmodule perl_module libexec/apache2/mod_perl.so alias /perl /library/webserver/perl <location /perl> sethandler perl-script perlresponsehandler modperl::registry options execcgi perlsendheader on order allow,deny allow </location>
if script saved in /library/webserver/perl/
can see mod_perl headers available now, i'd rather setup private installation of apache/mod_perl. macports makes lot easier...
Comments
Post a Comment