Difference between revisions of "Mod perl"

From ArchWiki
Jump to: navigation, search
m (add ja link)
 
(20 intermediate revisions by 6 users not shown)
Line 1: Line 1:
[[Category:Web Server]]
+
{{DISPLAYTITLE:mod_perl}}
{{stub}}
+
[[Category:Web server]]
== Enabling Perl + Apache ==
+
[[ja:Mod perl]]
 +
From the [http://perl.apache.org/ project]:
 +
:mod_perl brings together the full power of the Perl programming language and the [[Apache HTTP Server]]. You can use Perl to manage Apache, respond to requests for web pages and much more.
  
Install {{Pkg|mod_perl}} from the [[Official Repositories|official repositories]].
+
== Installation ==
  
Add this to {{ic|httpd.conf}}:
+
Install the {{AUR|mod_perl}} package.
 +
 
 +
== Configuration == 
 +
 
 +
Load the module via the main Apache configuration file {{ic|httpd.conf}}:
  
 
{{bc|
 
{{bc|
 
LoadModule perl_module modules/mod_perl.so
 
LoadModule perl_module modules/mod_perl.so
 
}}
 
}}
 +
 
===Allow perl to execute scripts for certain directories===
 
===Allow perl to execute scripts for certain directories===
  
There are two possible methods: creating a virtual host, or enabling
+
There are two possible methods to enable the {{ic|mod_perl}} module:  
perl for a subdirectory.
+
* [[#Using virtual hosts]], or  
 +
* [[#For a subdirectory]].
  
====Alternative 1: Using virtual hosts====
+
==== Using virtual hosts ====
Add a virtual host with various settings in extra/httpd-vhosts.conf:
+
  
{{bc|
+
Add a virtual host with settings. For example:
 +
 
 +
{{hc|/etc/httpd/conf/extra/httpd-vhosts.conf|
 
<VirtualHost perlwebtest:80>
 
<VirtualHost perlwebtest:80>
 
Servername perlwebtest
 
Servername perlwebtest
Line 36: Line 45:
 
}}
 
}}
  
Ensure {{ic|/etc/httpd/conf/httpd.conf}} includes the line
+
Ensure {{ic|/etc/httpd/conf/httpd.conf}} includes the created virtual host:
  
{{bc|
+
Include conf/extra/httpd-vhosts.conf
Include conf/extra/httpd-vhosts.conf
+
}}
+
  
 +
Make sure it does not have {{ic|Options Indexes FollowSymLinks}}!
  
Make sure you do not have "Options Indexes FollowSymLinks"!
+
Add "perlwebtest" as localhost in {{ic|/etc/hosts}}, using the machine's hostname for ''yourhostname'':
 +
127.0.0.1 localhost ''yourhostname'' perlwebtest
  
Add "perlwebtest" as localhost in {{ic|/etc/hosts}}:
+
==== For a subdirectory ====
{{bc|
+
127.0.0.1 localhost YOURHOSTNAME perlwebtest
+
}}
+
  
Use your hostname instead of {{ic|YOURHOSTNAME}}.
+
Add the following to the main configuration file:
  
====Alternative 2: Just enable for a certain subdirectory====
+
{{hc|{{ic|/etc/httpd/conf/httpd.conf}}|
Add the following to {{ic|/etc/httpd/conf/httpd.conf}}:
+
{{bc|
+
 
Alias /perlwebtest/ /srv/http/perlwebtest/
 
Alias /perlwebtest/ /srv/http/perlwebtest/
 
<Location /perlwebtest/>
 
<Location /perlwebtest/>
Line 96: Line 100:
 
}}
 
}}
  
Restart apache:
+
[[Restart]] apache's {{ic|httpd.service}} and let it [[reload]] the configuration.  
{{bc|
+
# rc.d restart httpd
+
}}
+
 
+
Usually you can just reload:
+
 
+
{{bc|
+
# rc.d reload httpd
+
}}
+
  
Then visit http://perlwebtest (if you created a virtual host) or
+
Finally, depending on chosen alternative configuration, visit  
http://localhost/perlwebtest (if you only enabled one directory).
+
* http://perlwebtest for [[#Using virtual hosts]], or
 +
* http://localhost/perlwebtest for [[#For a subdirectory]]

Latest revision as of 13:09, 14 June 2016

From the project:

mod_perl brings together the full power of the Perl programming language and the Apache HTTP Server. You can use Perl to manage Apache, respond to requests for web pages and much more.

Installation

Install the mod_perlAUR package.

Configuration

Load the module via the main Apache configuration file httpd.conf:

LoadModule perl_module modules/mod_perl.so

Allow perl to execute scripts for certain directories

There are two possible methods to enable the mod_perl module:

Using virtual hosts

Add a virtual host with settings. For example:

/etc/httpd/conf/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 created virtual host:

Include conf/extra/httpd-vhosts.conf

Make sure it does not have Options Indexes FollowSymLinks!

Add "perlwebtest" as localhost in /etc/hosts, using the machine's hostname for yourhostname:

127.0.0.1	localhost yourhostname perlwebtest

For a subdirectory

Add the following to the main configuration file:

/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's httpd.service and let it reload the configuration.

Finally, depending on chosen alternative configuration, visit