CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
First Post - Trying to get HelloWorld.cgi to work on Fed. 10

 



VernonDozier
Novice

Mar 25, 2009, 8:19 PM

Post #1 of 17 (2344 views)
First Post - Trying to get HelloWorld.cgi to work on Fed. 10 Can't Post

I've been pulling my hair out on this one all day. I'm trying to learn Perl/CGI and I'm just trying to make a simple Hello World. I've done it with xampp many times, but this time I am trying to use regular old Apache. Here it is. It's called HelloWorld.cgi:


Code
#!usr/bin/perl 


print "Content-Type: text/html\n\n";
print '<html>';
print '<body>';
print "Hello World";
print "</body>";
print "</html>";


The file is /var/www/html/HelloWorld.cgi

The result is that what is above is displayed in the browser, rather than simply Hello World. I've been playing around with the httpd.conf file all day, trying to follow the online advice, but failing. I've uploaded it as an attachment rather than posting it since it's so long and I'm sure many of you are quite familiar with it. It's pretty new to me though. Anyway, the attached is my current httpd.conf file. I still have the original too if I have to go back. Thanks.
Attachments: httpd.conf (33.1 KB)


FishMonger
Veteran / Moderator

Mar 26, 2009, 12:38 AM

Post #2 of 17 (2336 views)
Re: [VernonDozier] First Post - Trying to get HelloWorld.cgi to work on Fed. 10 [In reply to] Can't Post

Assuming you have a normal apache config, your script needs to be in the cgi-bin directory, not the html directory.


Tumata
User


Mar 26, 2009, 2:17 AM

Post #3 of 17 (2333 views)
Re: [FishMonger] First Post - Trying to get HelloWorld.cgi to work on Fed. 10 [In reply to] Can't Post

Sorry if I'm wrong but I've just looked throught his apache config and found nothing connected with perl at all Smile So I think that at first he needs load perl module (as I remember its name is mod_perl) and then associate .pl type with this module. So when somebody sends request to .pl script Apache pass this script to perl interpreter and send its output to user's browser.

P.S. Please, correct me if I'm wrong. Wink


FishMonger
Veteran / Moderator

Mar 26, 2009, 5:26 AM

Post #4 of 17 (2327 views)
Re: [Tumata] First Post - Trying to get HelloWorld.cgi to work on Fed. 10 [In reply to] Can't Post

No, mod_perl is not needed to execute Perl cgi scripts, but it does make them run faster.
http://en.wikipedia.org/wiki/Mod_perl

You might have been thinking about mod_cgi, which is being loaded (on line 198 of http.conf) with this command.
LoadModule cgi_module modules/mod_cgi.so

Further down is the ScriptAlias section (lines 556-574).

Code
# ScriptAlias: This controls which directories contain server scripts. 
# ScriptAliases are essentially the same as Aliases, except that
# documents in the realname directory are treated as applications and
# run by the server when requested rather than as documents sent to the client.
# The same rules about trailing "/" apply to ScriptAlias directives as to
# Alias.
#
ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"

#
# "/var/www/cgi-bin" should be changed to whatever your ScriptAliased
# CGI directory exists, if you have that configured.
#
<Directory "/var/www/cgi-bin">
AllowOverride All
Options ExecCGI
Order allow,deny
Allow from all
</Directory>



Tumata
User


Mar 26, 2009, 6:14 AM

Post #5 of 17 (2325 views)
Re: [FishMonger] First Post - Trying to get HelloWorld.cgi to work on Fed. 10 [In reply to] Can't Post

Yes. I was wrong. I was talking about how Apache server will understand how to process .pl file? What about adding such line into httpd.conf:

AddHandler cgi-script .pl

And also Perl script must be executable.

Does this help you?


FishMonger
Veteran / Moderator

Mar 26, 2009, 6:49 AM

Post #6 of 17 (2323 views)
Re: [Tumata] First Post - Trying to get HelloWorld.cgi to work on Fed. 10 [In reply to] Can't Post

Tumata ,

Instead of opening up possible security holes, what's wrong with simply moving the script to where apache expects to find scripts?

The ScriptAlias directory is already configured to execute these files as cgi scripts without adding the AddHandler cgi-script .pl statement


Tumata
User


Mar 26, 2009, 7:05 AM

Post #7 of 17 (2321 views)
Re: [FishMonger] First Post - Trying to get HelloWorld.cgi to work on Fed. 10 [In reply to] Can't Post

Ok. But could you describe this:

Code
<Directory "/var/www/html"> 

#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# http://httpd.apache.org/docs/2.2/mod/core.html#options
# for more information.
#
Options Indexes FollowSymLinks Includes ExecCGI

#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride All

#
# Controls who can get stuff from this server.
#
Order allow,deny
Allow from all

</Directory>


This directory also has ExecCGI.


Tumata
User


Mar 26, 2009, 7:22 AM

Post #8 of 17 (2315 views)
Re: [FishMonger] First Post - Trying to get HelloWorld.cgi to work on Fed. 10 [In reply to] Can't Post

FishMonger, I'm sorry if I am wrong. All of us make mistakes. But all what I want is to share my experience and learn sth new.


FishMonger
Veteran / Moderator

Mar 26, 2009, 7:52 AM

Post #9 of 17 (2312 views)
Re: [Tumata] First Post - Trying to get HelloWorld.cgi to work on Fed. 10 [In reply to] Can't Post


In Reply To
Ok. But could you describe this:

Code
<Directory "/var/www/html"> 

#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# http://httpd.apache.org/docs/2.2/mod/core.html#options
# for more information.
#
Options Indexes FollowSymLinks Includes ExecCGI

#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride All

#
# Controls who can get stuff from this server.
#
Order allow,deny
Allow from all

</Directory>


This directory also has ExecCGI.


Is there a part you do not understand?

Yes, that will allow cgi execution in the html directory, assuming you enabled the AddHandler directive as you suggested. I never said otherwise.

The point I was making was that enabling cgi in non ScriptAlias directories can open security holes which a beginner may not be aware of. Beginners should stick with the default setup until they learn about some of the implications and how to deal with them.


FishMonger
Veteran / Moderator

Mar 26, 2009, 7:55 AM

Post #10 of 17 (2311 views)
Re: [VernonDozier] First Post - Trying to get HelloWorld.cgi to work on Fed. 10 [In reply to] Can't Post

I just noticed that the shebang line is wrong.

change:

Code
#!usr/bin/perl


to:

Code
#!/usr/bin/perl



VernonDozier
Novice

Mar 26, 2009, 8:42 AM

Post #11 of 17 (2296 views)
Re: [FishMonger] First Post - Trying to get HelloWorld.cgi to work on Fed. 10 [In reply to] Can't Post


In Reply To
I just noticed that the shebang line is wrong.

change:

Code
#!usr/bin/perl


to:

Code
#!/usr/bin/perl




I really appreciate all of the replies. I cannot believe that I missed that, but I did, so I changed it, hoping that was the only problem. Alas, it is still displaying as plain text. Frown


VernonDozier
Novice

Mar 26, 2009, 8:49 AM

Post #12 of 17 (2293 views)
Re: [FishMonger] First Post - Trying to get HelloWorld.cgi to work on Fed. 10 [In reply to] Can't Post


In Reply To
Assuming you have a normal apache config, your script needs to be in the cgi-bin directory, not the html directory.


I appreciate the responses. If that is the way things are normally done, I guess I should do that. The reason I didn't originally is because I am not sure how to access it in the browser. Currently I have a directory called:

/var/www/html

That's where I have placed HelloWorld.cgi. In my browser, I have typed this:

http://localhost/HelloWorld.cgi

The cgi-bin directory is here:

/var/www/cgi-bin

If I were to place the file HelloWorld.cgi into the above directory, what should I type into my browser to get that page? As mentioned above, I have changed the top line. New file is this:


Code
#!/usr/bin/perl  


print "Content-Type: text/html\n\n";
print '<html>';
print '<body>';
print "Hello World";
print "</body>";
print "</html>";



FishMonger
Veteran / Moderator

Mar 26, 2009, 8:53 AM

Post #13 of 17 (2291 views)
Re: [VernonDozier] First Post - Trying to get HelloWorld.cgi to work on Fed. 10 [In reply to] Can't Post

What are the permission settings on the script?

In which directory is it placed, html or cgi-bin?

If it's in the html directory, then you'll need to enable the AddHandler directive.

Code
AddHandler cgi-script .cgi .pl

However, I still recommend moving it to the cgi-bin directory.


Tumata
User


Mar 26, 2009, 8:54 AM

Post #14 of 17 (2289 views)
Re: [VernonDozier] First Post - Trying to get HelloWorld.cgi to work on Fed. 10 [In reply to] Can't Post

You have an alias in httpd.conf. So you should type something like this:

http://localhost/cgi-bin/HelloWorld.cgi


FishMonger
Veteran / Moderator

Mar 26, 2009, 8:55 AM

Post #15 of 17 (2288 views)
Re: [VernonDozier] First Post - Trying to get HelloWorld.cgi to work on Fed. 10 [In reply to] Can't Post


Quote
/var/www/cgi-bin

If I were to place the file HelloWorld.cgi into the above directory, what should I type into my browser to get that page?


http://localhost/cgi-bin/HelloWorld.cgi


Tumata
User


Mar 26, 2009, 8:56 AM

Post #16 of 17 (2284 views)
Re: [FishMonger] First Post - Trying to get HelloWorld.cgi to work on Fed. 10 [In reply to] Can't Post

Smile


VernonDozier
Novice

Mar 26, 2009, 9:19 AM

Post #17 of 17 (2272 views)
Re: [FishMonger] First Post - Trying to get HelloWorld.cgi to work on Fed. 10 [In reply to] Can't Post

OK, good news. HelloWorld.pl and HelloWorld.cgi are both working in the /var/www/cgi-bin directory when I I type:

http://localhost/cgi-bin/HelloWorld.pl or
http://localhost/cgi-bin/HelloWorld.cgi

Regarding adding this line:

AddHandler cgi-script .cgi .pl

where would it go in the httpd.conf file? For example, if I wanted the following directories to allow cgi-bin:

/var/www/html/directory1
/var/www/html/directory2


would I add something like:


Code
<Directory "/var/www/html/directory1">  
AllowOverride All
Options ExecCGI
Order allow,deny
Allow from all
AddHandler cgi-script .cgi .pl
</Directory>
<Directory "/var/www/html/directory2">
AllowOverride All
Options ExecCGI
Order allow,deny
Allow from all
AddHandler cgi-script .cgi .pl
</Directory>


to the end of the file?

Regarding whether to keep everything in the cgi-bin folder, right now I'm at the experimentation stage, so I'm trying to learn how to specify directory permissions on a case by case basis, so I'd still like to learn how to do it, even if I end up taking the AddHandler line(s) out and putting them all in the cgi-bin folder.

Regarding where the files are located and their permissions, they are located currently in both the cgi-bin and the html folders, and I have double checked the permissions and they are all 0755.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives