Execute Perl .pl file on webpage?

edro

Lifer
Apr 5, 2002
24,326
68
91
How do I execute a .pl file in a webpage? If I go to the root directory now, then click on the file, it works.

I guess I could forward the URL to the actual file name...
 

Armitage

Banned
Feb 23, 2001
8,086
0
0
take a look at the docs for mod_perl
In particular, on linux/apache, you need to load the mod_perl module with some code like this:

#
# Mod_perl incorporates a Perl interpreter into the Apache web server,
# so that the Apache web server can directly execute Perl code.
# Mod_perl links the Perl runtime library into the Apache web server
# and provides an object-oriented Perl interface for Apache's C
# language API. The end result is a quicker CGI script turnaround
# process, since no external Perl interpreter has to be started.
#

LoadModule perl_module modules/mod_perl.so

# This will allow execution of mod_perl to compile your scripts to
# subroutines which it will execute directly, avoiding the costly
# compile process for most requests.
#
Alias /perl /var/www/perl
<Directory /var/www/perl>
SetHandler perl-script
PerlHandler ModPerl::Registry::handler
PerlOptions +ParseHeaders
Options +ExecCGI
</Directory>

This is from the file /etc/httpd/conf.d/perl.conf on my RedHat 9 system, slightly edited for my sitation.

I'm just learning this stuff, so other inputs are appreciated. You should also be able to run it as a CGI program without mod_perl, but I don't know how to do that, and mod_perl is supposed to be much faster.
 

notfred

Lifer
Feb 12, 2001
38,241
4
0
You don't NEED mod_perl at all.

How do you execute it? Just load up the URL of the script, if CGI is enabled on the webserver, it'll run.
 

edro

Lifer
Apr 5, 2002
24,326
68
91
Yeah, it works that way, but I want it to run on the address bar from the root URL.

Example: www.domain.com/script.pl -----> Works fine

I want it to execute that script when I go to www.domain.com

I have tried: <!--#exec cgi="/folder/script.pl"--> , but it does nothing.
 

Templeton

Senior member
Oct 9, 1999
467
0
0
This isn't a perl config issue, it's a http server issue. Assuming you are running apache, edit httpd.conf, look for a line like 'DirectoryIndex index.htm, etc...' add the filename you want served as an index to this line. Alternatively, and probably better, is to do this in a .htaccess file in the dir.