1

Reading the Mod_Perl module documentation, can we configure it on per domain basis, what I mean can we configure it to run on every domain or specific domain only.

What I see in the docs is:

Registry Scripts

To enable registry scripts add to httpd.conf:

Alias /perl/ /home/httpd/2.0/perl/
<Location /perl/>
SetHandler perl-script
PerlResponseHandler ModPerl::Registry
PerlOptions +ParseHeaders
Options +ExecCGI
</Location>

and now assuming that we have the following script:

#!/usr/bin/perl
print "Content-type: text/plain\n\n";
print "mod_perl 2.0 rocks!\n";

saved in /home/httpd/httpd-2.0/perl/rock.pl. Make the script executable and readable by everybody:

% chmod a+rx /home/httpd/httpd-2.0/perl/rock.pl

Of course the path to the script should be readable by the server too. In the real world you probably want to have a tighter permissions, but for the purpose of testing, that things are working, this is just fine.

From what I understand above, we can run Perl scripts only from one specific folder that we put the directive above. So the question again, can we make this directive per domain for all domains or for specific number of domains?

daliaessam
  • 111
  • 1

2 Answers2

0

The documentation you quoted is just an example. You can enable mod_perl Registry to run Perl scripts with a <Location> or even <LocationMatch> directive anywhere you want. If you want them only on certain domains, put them in <VirtualHost> directives and not outside of a VirtualHost.

  • Thanks for the info, I am not a server admin so very basic info needed, from what you are saying I just need to put the above code in the virtual host directive per each domain I want. Another issue, cpanel/WHM does not support Mod_Perl, is that possible automatically with cPanel and WHM, I am affraid cPanel will delete my settings if it does update it self ore rebuild the apache config files. –  Oct 08 '12 at 17:34
  • I have used mod_perl with cpanel/WHM before. Your web host will probably be willing to configure it for you. –  Oct 08 '12 at 22:50
0

After searching, digging, here are the steps in short and clear, per domain mod_perl installation and configuration.

install the mod_perl using cpan, from your shell:

%cpan
cpan> install mod_perl
cpan>exit

Login to your WHM, then:

*)- WHM: Main >> Service Configuration >> Apache Configuration >> Include Editor
        under Pre Main Include:
        LoadModule perl_module modules/mod_perl.so
        then click "Update"
*) -    Login as root from telnet.
*) -    % mkdir - p /usr/local/apache/conf/userdata/std/2/username/domain.com
*)- cd /usr/local/apache/conf/userdata/std/2/username/domain.com
*)- % pico custom.conf
*)- put this code in the file custom.conf:

  Alias /apps/ /home/username/public_html/apps/
  <Location /apps/>
      SetHandler perl-script
      PerlResponseHandler ModPerl::Registry
      PerlOptions +ParseHeaders
      Options +ExecCGI
      Order allow,deny
      Allow from all
  </Location>


*)- % /scripts/ensure_vhost_includes --all-users

*)- create the folder mkdir -p /home/username/public_html/apps/
*)- put a test script in the /home/username/public_html/apps/ folder
*)- call the test script: http://domain.com/apps/test.cgi
*)- the output should be:
    mod_perl 2.0 rocks!
    MOD_PERL: mod_perl/2.0.7
*)- replace username by the domain username, domain.com with the actual domain name. Also rename the apps folder to anything you want to run mod_perl scripts direct.

the test script test.cgi code is:

#!/usr/bin/perl
print "Content-type: text/plain\n\n";
print "mod_perl 2.0 rocks!\n";
#my $q = $ENV{MOD_PERL} ? CGI->new(shift @_) : CGI->new();
print "MOD_PERL: " . $ENV{MOD_PERL},"\n";

the cpanel in the httpd.conf says:

# To customize this VirtualHost use an include file at the following location
# Include "/usr/local/apache/conf/userdata/std/2/gamept/domain.com/*.conf"

Thanks all

daliaessam
  • 111
  • 1