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

Discussion in 'Perl Misc' started by petermichaux@yahoo.com, May 10, 2005.

  1. Guest

    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
    , May 10, 2005
    #1
    1. Advertising

  2. John Bokma Guest

    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
    John Bokma, May 10, 2005
    #2
    1. Advertising

  3. Guest

    wrote:
    > 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
    , May 10, 2005
    #3
  4. wrote:
    > 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.


    <snip>

    > 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

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
    Gunnar Hjalmarsson, May 10, 2005
    #4
  5. Guest

    Hi John,

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

    >> The only difference from that webpage is my configure file will

    parse
    >> ".shtml" files instead of ".html" files.


    >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?

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

    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
    , May 10, 2005
    #5
  6. Gunnar Hjalmarsson <> wrote in news:3ecahgF2br3qU1
    @individual.net:

    > wrote:


    ....

    >> 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


    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. Sinan Unur, May 10, 2005
    #6
  7. wrote in news:1115747652.929148.72670
    @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
    A. Sinan Unur, May 10, 2005
    #7
  8. Guest

    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
    , May 10, 2005
    #8
  9. A. Sinan Unur wrote:
    > Gunnar Hjalmarsson 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


    Thanks for the correction! Don't know why OS X made me think 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

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


    No, of course it's not.

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
    Gunnar Hjalmarsson, May 10, 2005
    #9
  10. wrote:
    > 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 ).

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
    Gunnar Hjalmarsson, May 10, 2005
    #10
  11. John Bokma Guest

    wrote:

    > Hi John,
    >
    > Thanks for the reply. Unfortunately it went over my head. Could you
    > clarify a few points
    >
    >>> The only difference from that webpage is my configure file will

    > parse
    >>> ".shtml" files instead of ".html" files.

    >
    >>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?


    ..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

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

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

    >
    > 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).

    --
    John Small Perl scripts: http://johnbokma.com/perl/
    Perl programmer available: http://castleamber.com/
    Happy Customers: http://castleamber.com/testimonials.html
    John Bokma, May 10, 2005
    #11
  12. John Bokma Guest

    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.

    --
    John Small Perl scripts: http://johnbokma.com/perl/
    Perl programmer available: http://castleamber.com/
    Happy Customers: http://castleamber.com/testimonials.html
    John Bokma, May 10, 2005
    #12
  13. Guest

    Gunnar Hjalmarsson <> wrote:
    > A. Sinan Unur wrote:
    >> Gunnar Hjalmarsson 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

    >
    > Thanks for the correction! Don't know why OS X made me think Windows...


    Shudder...!

    Axel

    >
    , May 10, 2005
    #13
  14. <> wrote:

    > 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


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
    Tad McClellan, May 11, 2005
    #14
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jiong Feng
    Replies:
    0
    Views:
    817
    Jiong Feng
    Nov 19, 2003
  2. Alex
    Replies:
    4
    Views:
    565
    Hasani Blackwell
    Feb 8, 2005
  3. =?Utf-8?B?S2VuTGVl?=
    Replies:
    5
    Views:
    2,708
  4. EdwardH

    Localhost isn't localhost

    EdwardH, Sep 29, 2005, in forum: Java
    Replies:
    20
    Views:
    6,383
    Roedy Green
    Oct 1, 2005
  5. Michael Vilain
    Replies:
    7
    Views:
    448
    Michael Vilain
    Feb 18, 2013
Loading...

Share This Page