Stas Bekman > DocSet-0.19 > Configure


Annotate this POD

View/Report Bugs


Configure Apache with Perl Example

Configure virtual hosts ^

With mod_perl, Perl code can be embedded directly in the Apache configuration file. Perl in httpd.conf is commonly used to dynamically configure Apache, but anything from URL translation to content generation can be accomplished directly in the configuation file within <Perl> sections.

This example reads configuration settings from a text file and configures Apache's virtual hosts.

The httpd.conf setup:

      my $config = "/etc/apache/vhosts.txt";
      open HOSTS, $config or die "Failed to open $config: $!";
      while (<HOSTS>) {
          my %config;
          my @params = qw/ServerName DocumentRoot ErrorLog TransferLog ServerAdmin/;
          @config{ @params } = split /\t/;
          $config{ Directory }{ $config{DocumentRoot} } = { Allow => 'from all' };
          push @{ $VirtualHost{''} }, \%config;
      close HOSTS;

See The Guide for other examples of configuring Apache with mod_perl.

« back
syntax highlighting: