mod_perl2 で Hello World!
なにごとも最初はHello World!
とりあえず作業記録は下記。
Make Documentroot
# mkdir -p /var/www/mydev/html
Make LIB Directory
# mkdir -p /var/www/mydev/lib/MyApp
Make script Directory
# mkdir /var/www/mydev/bin
Create startup.pl
# vi /var/www/mydev/bin/startup.pl
#! /usr/bin/perl use strict; use warnings; use lib qw(/var/www/mydev/lib); 1;
Create Hello World Module
# vi /var/www/mydev/lib/MyApp/Hello.pm
package MyApp::Hello; use strict; use warnings; use Apache2::RequestRec; use Apache2::RequestIO; use Apache2::Const -compile => 'OK'; sub handler : method { my $class = shift; my $r = shift; $r->content_type('text/plain'); $r->print('Hello! world!!'); return Apache2::Const::OK; } 1;
Apache2 configure
# cd /etc/httpd/conf.d # echo "LoadModule perl_module modules/mod_perl.so" > mod_perl.conf # vi virtual.conf
# Use name-based virtual hosting. # NameVirtualHost *:80 # # NOTE: NameVirtualHost cannot be used without a port specifier # (e.g. :80) if mod_ssl is being used, due to the nature of the # SSL protocol. # # # VirtualHost example: # Almost any Apache directive may go into a VirtualHost container. # The first VirtualHost section is used for requests without a known # server name. #ServerName localhost ServerAdmin webmaster@mydev.ent DocumentRoot /var/www/mydev/html ServerName mydev.ent ErrorLog logs/mydev.ent-error_log CustomLog logs/mydev.ent-access_log common # * mod_perl PerlModule mod_perl2 PerlRequire /var/www/mydev/bin/startup.pl PerlModule MyApp::Hello SetHandler perl-script PerlResponseHandler MyApp::Hello