1848686 Members
7088 Online
104035 Solutions
New Discussion

Re: perl

 
SOLVED
Go to solution
U.SivaKumar_2
Honored Contributor

perl

Hi,
I have a CGI perl script sample.pl in apache server . This script has to be used as index
page for the webserver. This script is put in
third subdirector under /cgi-bin/. What i want
is that users should not give the complete path to this perl script, But when they give
the website url like www.sample.com this script
should be called. ( like index.html )how can be
this achieved ?.

regards,
U.SivaKumar
Innovations are made when conventions are broken
7 REPLIES 7
Denver Osborn
Honored Contributor

Re: perl

one way to do it...

modify your httpd.conf file and make a change to the "DirectoryIndex" setting.

for this example, I set it to:

DirectoryIndex index.html index.pl

then create a symbolic link to your script.

ln -s /webdir/cgi-bin/script.pl /webdir/htdocs/index.pl

if there's an existing index.html file, move it aside.

Now when the address is pulled up, the index.pl file will be read and execute your script. (don't forget you have to restart apache 1st)

Hope this helps,
-denver
U.SivaKumar_2
Honored Contributor

Re: perl

Hi,
I have tried it already , But it displays the contents of the script. that's it.
I gave ExecCGI option to html root also. Still
problem persists.

Any ideas ?

regards,
U.SivaKumar
Innovations are made when conventions are broken
harry d brown jr
Honored Contributor

Re: perl


#
# DirectoryIndex: Name of the file or files to use as a pre-written HTML
# directory index. Separate multiple entries with spaces.
#

DirectoryIndex index.html index.php

Live Free or Die
Denver Osborn
Honored Contributor
Solution

Re: perl

Here are the changes I made to a default httpd.conf file.
____

## added +ExecCGI to options ##


Options Indexes FollowSymLinks +ExecCGI


## added .pl to AddHandler for cgi-script ##

AddHandler cgi-script .cgi .pl
____

Rather than add the .pl to AddHandler for cgi-script, I could've just made the link index.cgi and it would've executed the same... as long as I change the "DirectoryIndex" to contain whatever the link is named.

Since you're just getting the text of the script, check the "AddHandler cgi-script" then stop/start apache.

Hope this helps,
-denver
U.SivaKumar_2
Honored Contributor

Re: perl

Hi,
That worked , But the perl script gave error
that "can't locate perl.pl @INC" because perl.pl is located in original directory not
under www root directory.

Any ideas ?

regards,
U.SivaKumar
Innovations are made when conventions are broken
Denver Osborn
Honored Contributor

Re: perl

Does it fail after you add these variables to your script?
____

SCRIPT_FILENAME="/opt/hpapache2/cgi-bin/your_path/perl.pl"

SCRIPT_NAME="/cgi-bin/your_path/perl.pl"
____

I think this maybe getting more complicated than neccessary... was your intent to keep the path of this script from your users or simplify the way they access it (without havig to type full url?)

If your intent wasn't to hide the path of the script from your users and just simplify the way they access your site... create your index.html file with the following...


<meta http-equiv="Refresh" content="0;URL=http://www.yoursite.com/cgi-bin/yourpath/perl.pl" />


Hope this helps,
-denver
Allan Pincus
Frequent Advisor

Re: perl

Hi,

I did EXACTLY what you are talking about.

Stop your apache server, and edit your conf file. Modify the line:

From -

DirectoryIndex index.htm

To -

DirectoryIndex cgi-bin/myScript.pl

You can also set the shebang in the first line of your script:

#!/usr/bin/perl

or whereever your perl binary sits.

- Allan