Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

To Run perl through CGI

by sidvanga (Initiate)
on Oct 29, 2015 at 05:53 UTC ( [id://1146356]=perlquestion: print w/replies, xml ) Need Help??

sidvanga has asked for the wisdom of the Perl Monks concerning the following question:

Hi I am Very New to Perl. Learning perl online from last 2 to 3 days.

My question is:

How to run perl script as CGI in Ubunut machines I have tried it but didn't got succeed . Please help me.

I have googled it but didn't find many supporting tutorials for it.
Gone through one of the tutorial i have done exactly the same, But didn't worked.

Thank you all for your reponsese.
Here I am going to update my question.

I have kept my file at /var/www/cgi-bin/ and i have made following changes in /etc/apache2/apche2.conf

Alias /cgi-bin /var/www/cgi-bin/ <Directory /var/www/cgi-bin> AllowOverride None AddHandler cgi-script pl cgi Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch Order allow,deny Allow from all </Directory>
I have restarted Apache. found following error on apache error logs

attempt to invoke directory as script: /usr/lib/cgi-bin/ . When I have accessed through Url. And found following error on page
You don't have permission to access /cgi-bin/ on this server.
Though I have given the 0777 permission for directory "cgi-bin".

http://localhost/cgi-bin

I have kept my file "test.pl" under "cgi-bin" and when I am accessing it through URL. its giving 404 error.

code of test.pl
###Start### #!/usr/bin/perl print "Hello world"; ###End###

please help.
Thanks in Advance..!!!

Replies are listed 'Best First'.
Re: To Run perl through CGI
by kcott (Archbishop) on Oct 29, 2015 at 06:50 UTC
Re: To Run perl through CGI
by AnomalousMonk (Archbishop) on Oct 29, 2015 at 10:32 UTC
Re: To Run perl through CGI
by Anonymous Monk on Oct 29, 2015 at 06:13 UTC

    How to run perl script as CGI in Ubunut machines I have tried it but didn't got succeed Gone through one of the tutorial i have done exactly the same, But didn't worked.

    Which one? what did you do and what happened?

Re: To Run perl through CGI
by tonto (Friar) on Oct 29, 2015 at 19:34 UTC

    Did you configure Apache to run perl scripts from the directory where you have your perl script? Did you restart Apache as root after you finished the configuration? Did you make your perl script executable? What error message do you find in the Apache error log?

    Also, please post the test script that you're trying to run. There are many, many possible reasons why it doesn't work; that's why more details are required, as mentioned in previous replies.

      I have updated my question can you please help me out.
        Change
        Alias /cgi-bin /var/www/cgi-bin/
        to be
        ScriptAlias /cgi-bin/ /var/www/cgi-bin/
        (note use of ScriptAlias rather than Alias and the new trailing slash in the first string after ScriptAlias)

        Your test script cannot run because it is not a cgi script, so Apache cannot run it. Try this instead:

        #!/usr/bin/perl use strict; use warnings; print "Content-type: text/html\n\n"; print "<html>"; print "<header><title>Hello</title></header>"; print "<body>"; print "<p>Hello World!</p>\n"; print "</body>"; print "</html>"; 1;

        The next problem is your Apache configuration. What version is Apache? You can find that by typing this into a terminal:

        apachectl -V

        If your Apache is 2.4, you need to add this line to the configuration:

        Require all granted

        That goes at the bottom of your directory configuration. Also make the changes that davebaker and AnonymousMonk have mentioned.

Re: To Run perl through CGI
by Anonymous Monk on Nov 06, 2015 at 07:12 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1146356]
Approved by kcott
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (2)
As of 2025-07-20 03:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.