Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

and now assuming that we have the following script:

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

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

% chmod a+rx /home/httpd/httpd-2.0/perl/

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?

share|improve this question

migrated from Oct 10 '12 at 11:21

This question came from our site for professional and enthusiast programmers.

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.

share|improve this answer
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. – daliaessam Oct 8 '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. – Dondi Michael Stroma Oct 8 '12 at 22:50

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> install mod_perl

Login to your WHM, then:

*)- WHM: Main >> Service Configuration >> Apache Configuration >> Include Editor
        under Pre Main Include:
        LoadModule perl_module modules/
        then click "Update"
*) -    Login as root from telnet.
*) -    % mkdir - p /usr/local/apache/conf/userdata/std/2/username/
*)- cd /usr/local/apache/conf/userdata/std/2/username/
*)- % 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

*)- % /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:
*)- the output should be:
    mod_perl 2.0 rocks!
    MOD_PERL: mod_perl/2.0.7
*)- replace username by the domain username, 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:

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/*.conf"

Thanks all

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.