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



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,


--
John Small Perl scripts: http://johnbokma.com/perl/
Perl programmer available: http://castleamber.com/
Happy Customers: http://castleamber.com/testimonials.html

.



Relevant Pages

  • Re: [Way OT] perl, CGI, and sendmail
    ... >> Been experimenting with CGI, using perl. ... This is the standard format that came with the Debian install of apache ...
    (Debian-User)
  • Re: Apache and Perl in Windows
    ... The cgi scripts execute, ... I am studying a spider book that uses Perl so I ... > file in apache and rename the jar files in the server directory. ...
    (comp.lang.perl.misc)
  • Re: Perl And Apache.
    ... > After UserID/Password authentication on a web page, does Apache store the ... > UserID in an environment variable that a Perl script could use? ... if you are using the CGI module, you have access to any html form ...
    (comp.lang.perl.misc)
  • Re: Server permission problems and SchAgent
    ... > windows, apache, cgi, scheduler, perl. ... > I was using a CGI script in an Apache2/Win2k ...
    (microsoft.public.scripting.wsh)
  • Re: Server permission problems and SchAgent
    ... > windows, apache, cgi, scheduler, perl. ... > I was using a CGI script in an Apache2/Win2k ...
    (microsoft.public.scripting.vbscript)