Reputation: 5482
I am trying to make a simple program in perl. But whenever I try to run my file it always show the plain text instead of executing it.
Here is the code of my program I am working with:
#!/usr/bin/perl
print "Content-type: text/html\n\n";
print "<html>\n";
print "<title> PERL CGI</title>\n";
print "<body>";
print "hello perl-cgi!!!!!!!";
print "</body>";
print "</html>\n";
Upvotes: 1
Views: 1795
Reputation: 487
To run a '.pl or .pm' file in an Apache web server which has the compiler to execute, it should normally placed in a cgi-bin
folder. Else you should add following content in your .htaccess
file or in your Apache configuration file
.
AddHandler cgi-script .cgi .pl .pm
Options +ExecCGI
After that you should give the file permission
of that file as 755
Upvotes: 1
Reputation: 3461
It seems that you are trying to execute the CGI scripts. This CGI scripts can be a Perl Script, or a shell script, or C/C++ Program.
So You need to set up the HTTP server, so that whenever a file in a certain directory is requested, that file is not sent back; instead it is executed as a program, and whatever that program outputs is sent back for your browser to display. This function is called the Common Gateway Interface or CGI and the programs are called CGI scripts.
Again Before you proceed with CGI Programming, make sure that your Web Server supports CGI and it is configured to handle CGI Programs. All the CGI Programs will be executed by the HTTP server if kept in a pre-configured directory. This directory is called CGI Directory and by convention it is named as /cgi-bin. By convention PERL CGI files will have extension as .cgi.
Here is a simple link which is linked to a CGI script called hello.cgi. This file is being kept in /cgi-bin/ directory and it has following content. Before running your CGI program make sure you have chage
mode of file using chmod 755 hello.cgi UNIX command.
Code used for this hello.cgi is written below:
#!/usr/bin/perl
print "Content-type:text/html\r\n\r\n";
print '<html>';
print '<head>';
print '<title>Hello Word - First CGI Program</title>';
print '</head>';
print '<body>';
print '<h2>Hello Word! This is my first CGI program</h2>';
print '</body>';
print '</html>';
1;
Upvotes: 0
Reputation: 19204
You have to configure your web server to execute Perl scripts. There are several methods, the most simple is CGI
, and the alternatives are mod_perl
, FastCGI
and PSGI
. Configuration of each method depends on what HTTP server is used.
In case you use CGI in Apache2, make sure your script is executable (provided you use Linux/OSX/other UNIX: chmod +x hello.pl
), and directory containing your script has Options +ExecCGI
directive in Apache config file. Typically, /cgi-bin
directory is set up correctly for CGI scripts.
Consult your HTTP server documentation on how to configure it to serve dynamic content.
Upvotes: 0