Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Invoking Perl script from HTML in Apache Server

Status
Not open for further replies.

sbhatta

IS-IT--Management
Jan 26, 2012
4
AU
Hello,

This is a basic question but I could not find any other post answering this and hence I am posting it.

My perl script is simple and it looks like this:
====
#!/usr/bin/perl -w
print "Content-type: text/html\n\n";
print "banana";
====

The HTML file looks like this:
=======
<html>
<body>
apple <br>
<!--#exec cgi="/cgi-bin/test.pl"-->
orange <br>
</body>
</html>
========

However, when the HTML file is rendered on a browser, it does not display the "banana" part.

The strange part is that when the perl script is run standalone on the browser using the following URL, it works:


My question is:

1. Do I need any Apache webserver settings to make this happen? What settings are they?
2. Does it need any perl module to be installed at the webserver to make this happen? What are they?
3. Are there any other issues that will make this run?

I have been struggling with this for quiet some time. Any help would be much appreciated.

Regards
Shantanu
 
Hi

Shantanu said:
1. Do I need any Apache webserver settings to make this happen? What settings are they?
Have you read and followed Apache Tutorial: Introduction to Server Side Includes ? It describes what and how needs to be set up. Anyway, in 3 easy steps :
[ul]
[li]Load mod_include
Code:
[gray]# on your machine mod_include may have different location[/gray]
LoadModule include_module lib/apache/mod_include.so
[/li]
[li]Define how includes are handled
Code:
AddType text/html .shtml
AddOutputFilter INCLUDES .shtml
[/li]
[li]Allow includes
Code:
Options +Includes
[/li]
[/ul]
Shantanu said:
2. Does it need any perl module to be installed at the webserver to make this happen? What are they?
No. The code you posted works for me.
Shantanu said:
3. Are there any other issues that will make this run?
No. But note that not all files are parsed for SSI, only those with the extension you specified. With the usual configuration ( as shown above ) the HTML file needs .shtml extension.


Feherke.
 
Hi

When re-posting a question in another forum, please mention that fact.
Reading the earlier discussion in thread219-1673111 sometimes helps.

By the way, in this simple case both of these works :
Shantanu in the original thread said:
1. <!--#include virtual="/cgi-bin/test.pl" -->
2. <!--#exec cgi="/cgi-bin/test.pl" -->
But as the mod_include documentation says :
Apache Module mod_include said:
[tt]include virtual[/tt] should be used in preference to [tt]exec cgi[/tt] to include the output of CGI programs into an HTML document.

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top