Help getting Perl/CGI running on OS X localhost with apache

P

petermichaux

Hi,

I am trying to learn about perl and cgi. I have apache and php running
on my OS X (10.3) localhost. I followed the instructions on the
following site to configure apache for perl my modifying the file
"/etc/httpd/httpd.conf" on my computer.

http://www.cgi101.com/book/connect/mac.html

The only difference from that webpage is my configure file will parse
".shtml" files instead of ".html" files.

I have written a file called "first.cgi" and saved it in my sites
folder.

#!/usr/bin/perl -w
print "Content-type: text/html\n\n";
print "Hello, World!\n";

At the terminal command line I can successfully run the command "perl
first.cgi".

When i point my browser to "http://localhost/~peter/first.cgi" I get
the following message

Forbidden
You don't have permission to access /~peter/first.cgi on this server.
Apache/1.3.33 Server at peter-michauxs-computer.local Port 80

I tried using the terminal command "chmod 755 first.cgi". It looks like
the permissions are set correctly

-rwxr-xr-x 1 peter peter 108 9 May 23:14 first.cgi*

The forbidden message did not go away. What's going wrong? Is apache
not configured correctly? Do i need any extra files in my sites folder?

Any help greatly appreciated!!!!!

Thanks,
Peter
 
J

John Bokma

wrote:
Hi,

I am trying to learn about perl and cgi. I have apache and php running
on my OS X (10.3) localhost. I followed the instructions on the
following site to configure apache for perl my modifying the file
"/etc/httpd/httpd.conf" on my computer.

http://www.cgi101.com/book/connect/mac.html

The only difference from that webpage is my configure file will parse
".shtml" files instead of ".html" files.

shtml = SSI, not CGI
I have written a file called "first.cgi" and saved it in my sites
folder.

Use a cgi-bin dir *outside* your document root.
#!/usr/bin/perl -w

use warnings; # instead of -w
use strict;

Also, use -T.
print "Content-type: text/html\n\n";

Be careful with printing your own headers...

You can use <<HERE docs, eg.

print <<HELLO;
Content-type: text/plain

Hello, World!
HELLO

(note that what you served was not valid HTML, hence I changed the
content-type to plain).
The forbidden message did not go away. What's going wrong? Is apache
not configured correctly? Do i need any extra files in my sites
folder?

make a cgi-bin directory in the *parent* of your Document Root, e.g.

cgi-bin
htdocs

next you need:

ScriptAlias /cgi-bin/ "/absolute/path/to/cgi-bin/"

<Directory "/absolute/path/to/cgi-bin">
AllowOverride None
Options None
Order allow,deny
Allow from all
</Directory>

Note that the second path has *no* trailing / and the first *has*.

If you are serious in developing stuff I recommend using virtual hosts,
see: http://johnbokma.com/mexit/2005/01/05/apache-httpd-conf-split.html

Check your error_log, I often use:

tail -f logs/error_log

HTH,
 
A

axel

When i point my browser to "http://localhost/~peter/first.cgi" I get
the following message

Forbidden
You don't have permission to access /~peter/first.cgi on this server.
Apache/1.3.33 Server at peter-michauxs-computer.local Port 80

I tried using the terminal command "chmod 755 first.cgi". It looks like
the permissions are set correctly

-rwxr-xr-x 1 peter peter 108 9 May 23:14 first.cgi*

The forbidden message did not go away. What's going wrong? Is apache
not configured correctly? Do i need any extra files in my sites folder?

Have you checked that the permissions on the directory allow access?
Quick check: copy first.cgi to first.html and see if the perl script is
displayed as text.

Otherwise it seems like an Apache configuration issue (perhaps CGI scripts
are not enabled in user directories).

Axel
 
G

Gunnar Hjalmarsson

I am trying to learn about perl and cgi.

That's fine. If you need help with Perl, this is a good place to ask.
Btw, please study the posting guidelines:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html

You'd better not bring up CGI questions here, unless the problem is
related to the use of any of the CPAN modules for dealing with CGI
tasks. Other CGI questions are better asked in
comp.infosystems.www.authoring.cgi.
I have apache and php running on my OS X (10.3) localhost.

When i point my browser to "http://localhost/~peter/first.cgi" I get
the following message

Forbidden
You don't have permission to access /~peter/first.cgi on this server.
Apache/1.3.33 Server at peter-michauxs-computer.local Port 80

That's an Apache configuration problem, which is even more off topic in
this group. You may want to try this group instead:

comp.infosystems.www.servers.ms-windows

OTOH, if you want to avoid the hazzle you are currently experiencing,
why not try the bundle at http://www.indigostar.com/indigoperl.htm
 
P

petermichaux

Hi John,

Thanks for the reply. Unfortunately it went over my head. Could you
clarify a few points
shtml = SSI, not CGI

Will this affect my first.cgi test since i am directing my browser to
the actual cgi file? So what should I do?
folder.

Use a cgi-bin dir *outside* your document root.

My sites folder is "/users/peter/Sites". What should the cgi-bin
directory be?

I cannot understand what you complete first.cgi file would be with the
modifications you have suggested. I have seen other hello world files
like mine suggested on the internet. I'm surprised that you seem to say
it is not even close to correct.

I do not understand "make a cgi-bin directory in the *parent* of your
Document Root, e.g....". Where would cgi-bin and htdocs be in relation
to "/users/peter/Sites"?

Sorry, I guess I need a bit more hand holding to get started. But I am
really interested.

Thanks,
Peter
 
A

A. Sinan Unur

(e-mail address removed) wrote:
....


That's an Apache configuration problem, which is even more off topic in
this group. You may want to try this group instead:

comp.infosystems.www.servers.ms-windows

He is on OS X, which is based on BSD Unix so, he'll probably have better
luck in

comp.infosystems.www.servers.unix
comp.infosystems.www.servers.mac
OTOH, if you want to avoid the hazzle you are currently experiencing,
why not try the bundle at http://www.indigostar.com/indigoperl.htm

I don't think that is available for OS X.

Sinan
 
A

A. Sinan Unur

(e-mail address removed) wrote in @o13g2000cwo.googlegroups.com:
My sites folder is "/users/peter/Sites". What should the cgi-bin
directory be?

I cannot understand what you complete first.cgi file would be with the
modifications you have suggested. I have seen other hello world files
like mine suggested on the internet. I'm surprised that you seem to say
it is not even close to correct.

I do not understand "make a cgi-bin directory in the *parent* of your
Document Root, e.g....". Where would cgi-bin and htdocs be in relation
to "/users/peter/Sites"?

Sorry, I guess I need a bit more hand holding to get started. But I am
really interested.

Good for you. However, what you are interested in, currently, does not have
anything to do with Perl.

You have an Apache configuration issue. Thus, you should read about Apache
configuration, and ask questions on the relevant fora.

Sinan
 
P

petermichaux

The off topic messages did not appear until after I posted my second
message. It seemed like one person did not mind the question so I
continued. Rough crowd 'round here.

As far as _perl_ goes, is my file "first.cgi" acceptable for what I am
trying to do? John does not think it will work.

#!/usr/bin/perl -w
print "Content-type: text/html\n\n";
print "Hello, World!\n";

Thanks,
Peter
 
G

Gunnar Hjalmarsson

Rough crowd 'round here.

If you consider the volume of messages in this group, you'll likely
understand why we point out when somebody brings up an off topic problem.
As far as _perl_ goes, is my file "first.cgi" acceptable for what I am
trying to do? John does not think it will work.

John didn't say it won't work, but he suggested a couple of alternative
ways to do it.
#!/usr/bin/perl -w
print "Content-type: text/html\n\n";
print "Hello, World!\n";

That's a perfectly fine script for testing purposes ( provided that the
path to the Perl interpreter actually is /usr/bin/perl ).
 
J

John Bokma

wrote:
Hi John,

Thanks for the reply. Unfortunately it went over my head. Could you
clarify a few points



Will this affect my first.cgi test since i am directing my browser to
the actual cgi file? So what should I do?

..shtml is parsed HTML, you can call a script using SSI directives.

cgi is more commonly used like:

http://example.com/cgi-bin/helloworld.cgi
My sites folder is "/users/peter/Sites". What should the cgi-bin
directory be?

if you put index.html in Sites, and you see the index.html if you go to
http://localhost/ your document root is /users/peter/Sites. More safe:
search in your httpd.conf for DocumentRoot and check its value.
I cannot understand what you complete first.cgi file would be with the
modifications you have suggested.

/usr/bin/perl -T

use strict;
use warnings;

print <<HELLO;
Content-type: text/plain

Hello, World!
HELLO

(untested)
I have seen other hello world files
like mine suggested on the internet. I'm surprised that you seem to
say it is not even close to correct.

This holds for an amazing number of CGI scripts you will find. Most will
be extremely badly written. A huge number are developed using trial and
error, which often means: find a script, change lines until it works,
make it available. In short, most scripts you find are insecure, garbage
and an extremely bad start for anyone wanting to learn CGI.
I do not understand "make a cgi-bin directory in the *parent* of your
Document Root, e.g....". Where would cgi-bin and htdocs be in relation
to "/users/peter/Sites"?
/users/peter/cgi-bin

Sorry, I guess I need a bit more hand holding to get started. But I am
really interested.

Normally Apache set up questions should be asked in an Apache related
group.

Oh, and cgi-bin should be readable by your Apache process. 711 often
does the trick. If you can turn one 1 into 0, do so. (Same for the 5 in
755, if you can turn a 5 in a 0 do so).
 
J

John Bokma

wrote:
The off topic messages did not appear until after I posted my second
message. It seemed like one person did not mind the question so I
continued. Rough crowd 'round here.

As far as _perl_ goes, is my file "first.cgi" acceptable for what I am
trying to do? John does not think it will work.

#!/usr/bin/perl -w
print "Content-type: text/html\n\n";
print "Hello, World!\n";

Oh, it will work. But you suggest that it's html, which it's not. Adding
use strict and use warnings might help you later on, as will the -T switch.

In the future:

use CGI;
use CGI::Carp 'fatalsToBrowser';

instead of hacking your own QUERY_STRING decoding stuff (or horror: cut &
paste it from a cgi script you found somewhere) might save you a serious
headache.

Golden rule: You can't learn programming by cut and paste until it works.
 
T

Tad McClellan

I am trying to learn about perl and cgi.


Have you checked the Perl FAQs that mention the CGI?

perldoc -q CGI

Where can I learn about CGI or Web programming in Perl?

What is the correct form of response from a CGI script?

My CGI script runs from the command line but not the browser. (500
Server Error)

How can I get better error messages from a CGI program?

How do I make sure users can't enter values into a form that cause my
CGI script to do bad things?

How do I decode a CGI form?

The only difference from that webpage is my configure file will parse
".shtml" files instead of ".html" files.


Get it to work with .html first.

Once that is working, then move on to getting it to work with secure HTML.

print "Content-type: text/html\n\n";
print "Hello, World!\n";


You shouldn't say that you will be giving HTML unless you actually
give HTML.

Your output looks a lot more line text/plain than text/html.

At the terminal command line I can successfully run the command "perl
first.cgi".


Then you do not have a Perl problem, your problem is somewhere else.

When i point my browser to "http://localhost/~peter/first.cgi" I get
the following message

Forbidden
You don't have permission to access /~peter/first.cgi on this server.

Is apache
not configured correctly?


Yes, your web server appears to be not configured correctly.

Do i need any extra files in my sites folder?


I dunno, we help with Perl here.

Folks that can help with server setup hang out somewhere else.

Any help greatly appreciated!!!!!


Ask Perl questions in a Perl newsgroup.

Ask server setup questions in a server newsgroup, such as:

comp.infosystems.www.servers.mac
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,708
Latest member
SherleneF1

Latest Threads

Top