Difference between revisions of "Mod perl"

From ArchWiki
Jump to: navigation, search
Line 10: Line 10:
 
LoadModule perl_module modules/mod_perl.so
 
LoadModule perl_module modules/mod_perl.so
 
}}
 
}}
 +
===Allow perl to execute scripts for certain directories===
  
 +
There are two possible methods: creating a virtual host, or enabling
 +
perl for a subdirectory.
 +
 +
====Alternative 1: Using virtual hosts====
 
Add a virtual host with various settings in extra/httpd-vhosts.conf:
 
Add a virtual host with various settings in extra/httpd-vhosts.conf:
  
Line 31: Line 36:
 
}}
 
}}
  
Ensure /etc/httpd/conf/httpd.conf includes the line <code>Include conf/extra/httpd-vhosts.conf</code>.
+
Ensure {{ic|/etc/httpd/conf/httpd.conf}} includes the line  
 +
 
 +
{{bc|
 +
Include conf/extra/httpd-vhosts.conf
 +
}}
 +
 
  
 
Make sure you do not have "Options Indexes FollowSymLinks"!
 
Make sure you do not have "Options Indexes FollowSymLinks"!
Line 42: Line 52:
 
Use your hostname instead of {{ic|YOURHOSTNAME}}.
 
Use your hostname instead of {{ic|YOURHOSTNAME}}.
  
Create {{ic|perl_module.conf}} as well (same directory as {{ic|httpd-vhosts.conf}}):
+
====Alternative 2: Just enable for a certain subdirectory====
 +
Add the following to {{ic|/etc/httpd/conf/httpd.conf}}:
 +
{{bc|
 +
Alias /perlwebtest/ /srv/http/perlwebtest/
 +
<Location /perlwebtest/>
 +
      AddHandler perl-script .pl
 +
      AddHandler perl-script .cgi
 +
      PerlResponseHandler ModPerl::Registry
 +
      PerlOptions +ParseHeaders
 +
      Options +ExecCGI
 +
      Order allow,deny
 +
      Allow from all
 +
</Location>
 +
}}
 +
 
 +
===Turn on perl for directory listings===
 +
Create {{ic|/etc/httpd/conf/extra/perl_module.conf}} as well:
  
 
{{bc|
 
{{bc|
Line 54: Line 80:
 
}}
 
}}
  
Then include it in httpd.conf:
+
Then include it in {{ic|/etc/httpd/conf/httpd.conf}}:
  
 
{{bc|
 
{{bc|
Line 61: Line 87:
 
}}
 
}}
  
 +
===Try it out===
 
Create {{ic|index.pl}} in {{ic|/srv/http/perlwebtest}}:
 
Create {{ic|index.pl}} in {{ic|/srv/http/perlwebtest}}:
  
Line 80: Line 107:
 
}}
 
}}
  
Then visit http://localhost/.
+
Then visit http://perlwebtest (if you created a virtual host) or
 +
http://localhost/perlwebtest (if you only enabled one directory).

Revision as of 09:45, 30 August 2012

Tango-document-new.pngThis article is a stub.Tango-document-new.png

Notes: please use the first argument of the template to provide more detailed indications. (Discuss in Talk:Mod perl#)

Enabling Perl + Apache

Install mod_perl from the official repositories.

Add this to httpd.conf:

LoadModule perl_module modules/mod_perl.so

Allow perl to execute scripts for certain directories

There are two possible methods: creating a virtual host, or enabling perl for a subdirectory.

Alternative 1: Using virtual hosts

Add a virtual host with various settings in extra/httpd-vhosts.conf:

<VirtualHost perlwebtest:80>
	Servername perlwebtest
	DocumentRoot /srv/http/perlwebtest
	ErrorLog /var/log/httpd/perlwebtest-error.log
	CustomLog /var/log/httpd/perlwebtest-access.log combined
	<Directory /srv/http/perlwebtest>
		AddHandler perl-script .pl
		PerlResponseHandler ModPerl::Registry
		Options +ExecCGI
		PerlOptions +ParseHeaders
		AllowOverride All
		Order allow,deny
		Allow from all
	</Directory>
</VirtualHost>

Ensure /etc/httpd/conf/httpd.conf includes the line

Include conf/extra/httpd-vhosts.conf


Make sure you do not have "Options Indexes FollowSymLinks"!

Add "perlwebtest" as localhost in /etc/hosts:

127.0.0.1	localhost YOURHOSTNAME perlwebtest

Use your hostname instead of YOURHOSTNAME.

Alternative 2: Just enable for a certain subdirectory

Add the following to /etc/httpd/conf/httpd.conf:

Alias /perlwebtest/ /srv/http/perlwebtest/
<Location /perlwebtest/>
      AddHandler perl-script .pl
      AddHandler perl-script .cgi
      PerlResponseHandler ModPerl::Registry
      PerlOptions +ParseHeaders
      Options +ExecCGI
      Order allow,deny
      Allow from all
</Location>

Turn on perl for directory listings

Create /etc/httpd/conf/extra/perl_module.conf as well:

# Required modules: dir_module, perl_module

<IfModule dir_module>
        <IfModule perl_module>
                DirectoryIndex index.pl index.html
        </IfModule>
</IfModule>

Then include it in /etc/httpd/conf/httpd.conf:

# Perl
Include conf/extra/perl_module.conf

Try it out

Create index.pl in /srv/http/perlwebtest:

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

Restart apache:

# rc.d restart httpd

Usually you can just reload:

# rc.d reload httpd

Then visit http://perlwebtest (if you created a virtual host) or http://localhost/perlwebtest (if you only enabled one directory).