Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 20 Aug 2004 11:10:10 -0400
From:      Bill Moran <wmoran@potentialtech.com>
To:        Mark Jayson Alvarez <jay2xra@yahoo.com>
Cc:        freebsd-questions@freebsd.org
Subject:   Re: Humble questions for web developers in freebsd.
Message-ID:  <20040820111010.7b74594b.wmoran@potentialtech.com>
In-Reply-To: <20040820145201.68204.qmail@web51603.mail.yahoo.com>
References:  <20040820145201.68204.qmail@web51603.mail.yahoo.com>

next in thread | previous in thread | raw e-mail | index | archive | help
Mark Jayson Alvarez <jay2xra@yahoo.com> wrote:
> Greetings, 
>  
>       I have installed the latest Apache http server
> for the first time and I have just started programming
> perl cgi scripts as well. It didn't brought me any
> trouble installing it, but when I wrote my first
> "Hello World" cgi script, I end up with an internal
> server error. Eventually (through a very intensive,
> sleepless researching), I was able to run it
> successfully  
> in a browser after changing its mode to 755(whiew!). 
>  
> Questions: 
> 1. Do I always have to do this for every script that I
> would make? I thought, apache web server will know how
> to execute those files if it sees something like
> #!/usr/local/bin/perl in the beginning of the file.

No.  Apache needs to know that those script should be executed instead
of sent as-is to the browser.  This is more a Unix thing than a CGI thing.
Scripts should always have execute permissions on them, but Apache can be
configured to work around this by identifying the type of file and
handling it properly.  Lots of docs available for reading, especially on
Apache's config.

> 2. I'm having a small clue on this one. The perl
> book("Beginning Perl") told me that in a default
> installation, apache is started by "nobody"(after
> running"ps -aux |grep httpd", I can see at least five
> httpd processes run by nobody and one that is run by
> me(root).) --if it is run by nobody, then it can't run
> the cgi script I have written right? Elucidate me
> please.  (And also those 5 nobody's) 

How did you install Apache?  Default Apache installs on FreeBSD use
user "www" and group "www" and no longer use nobody.

The first Apache process has to start as root to bind to port 80, but
any additional worker process should run as a non-priviledged user.
(usually user www on FreeBSD)

> 1. (hmm.. just curious) Can't I start writing a perl
> program or just a plain text file that already has a
> 755 mode?(ex: vi  -m 755... hello.plx) 

I don't see why not.

> 2. Do you know how can I run a perl program in freebsd
> without having it preceded with the word perl? 
> (I tried changing its mode to 755 and also putting it
> to /usr/local/bin but it didn't work(don't laugh at me
> please.. I'm still learning:=).

Just call the program.  If it has X permissions for available for you
(the user you're trying to run it as) it will notice the #!/usr/bin/perl
at the head of the file an user perl to interpret the script.  I noticed
you had #!/usr/local/bin/perl in your earlier comments.  Use "which perl"
to find out the path to perl on your system and use that.  If that first
line has the wrong path, your scripts won't run.

> 3. If you happened to be one, I'm already having a
> picture of how web developers are creating web pages
> or cgi scripts(because the whole apache directory is
> owned by the root, they would have to write them
> outside and then transfer them inside when they are
> finish, am I correct?? Because what I did was, change
> the ownership of the entire apache directory for me to
> be able to save an html file or a cgi script in it... 

Make each directory owned by the user doing development, and the group
of the web server (usually www, although it appears to be nobody in
your case).  Then the user can have full access to the file, and you
can give the group r-x permissions so it can read and execute it.

> 4. Do you happen know any good link where I can learn
> how to write shell scripts so that I may be able to
> start an application at boot time by putting it in
> "/usr/local/etc/rc.d" (ex: httpd) 

The existing shell scripts in that directory, placed there by programs
you installed are a good start.

Otherwise, there's a section in the handbook on the rcng system that's
pretty informative.

-- 
Bill Moran
Potential Technologies
http://www.potentialtech.com



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20040820111010.7b74594b.wmoran>