Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Apache ignores ARGV[0] request

by Anonymous Monk
on Feb 07, 2005 at 02:27 UTC ( [id://428548]=perlquestion: print w/replies, xml ) Need Help??

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

Hi, I've been searching for an answer to this and can't find anything like it ... although I think that the fix will end up being simple. The following code runs on a commercial server I have access to, and generates the calendar I want. When I run it on my RedHat 9.0 Linux box running Apache and mod_perl, though, it runs, but $ARGV[0] never makes it to $Month so it doesn't generate the calendar. I don't get any errors except that I am trying to use a variable ($Month) that has not been initialized. I have tried other scripts that I know to work and they also fail to pass the $ARGV[0]. I don't know if this matters, but I had problems running scripts from Apache at all until I installed the mod_perl module ... perl runs fine from the command line, though.
#! /usr/local/bin/perl -w my $Month = $ARGV[0]; use strict; #$Month = 3; # if I uncomment this like it also works fine print "Content-type: text/html\n\n"; print "<html>\n <head>\n <title>file viewer</title>\n </head>\n"; print "<body>\n"; print @ARGV; #this shows nothing on my Apache server &Calendar($Month,2005,1); #Print a calendar for a month in 2005 print "</body></html>\n";
Thanks so much! Saands

Replies are listed 'Best First'.
Re: Apache ignores ARGV[0] request
by Tanktalus (Canon) on Feb 07, 2005 at 02:33 UTC

    Um ... Apache doesn't pass in arguments on the commandline - because that's not what the CGI spec says. I'd suggest reading the CGI module's documentation for a lot of information on this - that's where I learned how to deal with Apache, and it has worked wonderfully.

    After reading the CGI module's docs, I'd suggest CGI::Application and HTML::Template as your next steps into CGI programming. They take a lot of the tedium out, and you can get to the fun parts of coding much faster.

      Hmmmm ... so that must mean that the commercially hosted site I tested it on runs a web server other than apache? I guess I just imagined that everyone on x-nux was using Apache. My bad. I guess I'll need to go back to the books. Thanks.

        Most do run Apache, but most do not run mod_perl. This has to do with security issues on shared machines.

        As far as cgi not working with Apache, that is probably a settings issue. First, mod_cgi has to be enabled in Apache, and secondly, the directory that your script is in has to be configured within apache (through a .conf file or a .htaccess file) to allow the execution of scripts.

        These are not the only potential issues, permissions being another, but these are the ones most people have issues with the most. Is the configuration of your local machine set up to run the perl script as a cgi script? I would be willing to bet that the directory you have your script in is not set up to run cgi.

        Something like this in a .htaccess file in the directory you want the script to run as a cgi:

        DirectoryIndex index.pl Options +ExecCGI AddHandler cgi-script .cgi .pl
        and then, in the httpd.conf somewhere, put
        ScriptAlias /cgi-bin/ "/path/to/script/directory/"
        You can use an index.pl script to log efforts to directly access the cgi-bin directory, create your own error page, or whatever. I use this to monitor for attempted cracks into the system. It has actually worked well in stopping some. Returning their IP address after a few tries on a page that says illegal access attempt logged scares most kiddies off. You can also do without it. The fewer things a stranger has access to, the safer you are.

        I would develop the code in as much the same environment as what I was going to place it in, so if the host uses cgi-bin, I would use cgi-bin. This helps down the road by eliminating potential issues with differences in environments, like using mod_perl to develop in, but then using cgi to run in production. Bad combination. I would also try to keep my scripts in a directory that is not in the public_html path. Most hosts I work with allow that and it is much more secure.

        Good luck to you.
        digiryde
Re: Apache ignores ARGV[0] request
by perrin (Chancellor) on Feb 07, 2005 at 02:32 UTC
    How do you call this script when it works? You should be using something like the CGI module, not reading @ARGV. It also sounds like you don't really understand the difference between CGI and mod_perl. You do not need mod_perl to run perl scripts under CGI.
      When it works, I call it with: www.commercialserver.com/cgi-bin/fileview.pl?2 When it doesn't work, I call it with: www.myserver.com/perl/fileview.pl?2 You are correct that I'm not terribly clear about the ramifications of mod_perl, but since it seemed that my Apache was unable to access the standard install of perl, I got desperate and "brought it inside" so to speak with mod_perl. It is ENTIRELY possible that I have a config problem with Apache, but I can't find it if it exists :>( Thanks ...
        It sounds like you are running it through mod_perl via Apache::Registry. It will not populate STDIN for you the same way that CGI does. You need to either go back to using CGI, which should work fine but you may need a little help, or switch from grabbing the args yourself to using something like the CGI module.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (8)
As of 2024-04-23 09:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found