1
votes

Before we begin, I want to say that I have read this: Perl Apache : Perl script displayed as plain text

I've read it, tried the things, didn't work out (Sadly)

I am on Ubuntu

I want to run cgi scripts, they compile fine, I have the appropriate rights to the folder (atleast I don't get an error that I don't when I try to enter it through the browser)and the files run as plain text.

First the file which I am trying to run:

 #!/usr/bin/perl

 use CGI qw/:standard/;
 print header,
 h1('CGI.pm is simple.'),
 end_html; 

And I get as output the source code.

The path to the folder is /var/www/a2/

and the configuration in the apache .config file is:

ScriptAlias /a2/ /var/www/a2/
<Directory "/var/www/a2">
AddHandler cgi-script .cgi .pl
AllowOverride None
Options ExecCGI
Order allow,deny
Allow from all
</Directory>

The file compiles fine and prints the html in the terminal.

My only guess is that I have not given proper rights to the file.

EDIT: I checked the error log. It doesn't give an error for this.

EDIT: After a very long discussion with Mark Setchell the error was discovered. I had posted this in the wrong .config file and I had been using the wrong (unconfigured folder) all along.

3

3 Answers

1
votes

Here are some things to try:

  1. Ensure your script is named with the extension ".pl"

  2. Ensure your script is executable. Do this by typing:

    chmod +x yourscript.pl

  3. As Mark says, ensure you have the shebang as the very first line of your script:

    #!/usr/bin/perl

  4. Remove the "1;" at the end, you only need that for packages/modules.

0
votes

I don't see a

#!/usr/bin/perl

at the top of your script. Without it, the CGI handler won't know how to execute it.

0
votes

Make sure apache cgi mode is enable

sudo a2enmod cgi   //will enable the cgi mode
sudo service apache2 restart

Make sure that the file permission to the .cgi file is okay

sudo chmod 755 yourFile.cgi

Try executing it through terminal

perl /Path_To_The_File/fileName.cgi

Ensure that your fileName.cgi contains bellow code at top of the file

#!/usr/bin/perl -w

print "Content-type: text/html\n\n";