Обсуждение: Perl Script and Postgres DB running via Apache Web Server

Поиск
Список
Период
Сортировка

Perl Script and Postgres DB running via Apache Web Server

От
Carla J Breuker
Дата:
Hi...

I have the following Perl Script (with Postgres code):

    #!/usr/bin/perl -w
    use Pg;

    print "<HTML><P>This is a test</HTML"

    $conn = Pg::connectdb("dbname=test");
    $conn->exec("insert into test_table values ('Carla', '90')");

This Script will run from the command line, and inserts values into the
existing DB and table.
When it is run via the web browser, nothing happens (browser hangs).

The script is in the /usr/local/httpd/cgi-bin directory, owned by a user
(not root), and has 755 permissions.

We have exhaustively searched perl, cgi, postgres, and apache
documentation both printed and web-based,
and cannot determine how to correct this problem.

We suspect that it may be a permissions / execution rights for the httpd,
but we are stumped.

Any help will be greatly appreciated.

Thanks,
    -Carla and Chris :)
________________________________________________________________
YOU'RE PAYING TOO MUCH FOR THE INTERNET!
Juno now offers FREE Internet Access!
Try it today - there's no risk!  For your FREE software, visit:
http://dl.www.juno.com/get/tagj.

Re: Perl Script and Postgres DB running via Apache Web Server

От
phawkins@connact.com (Patricia Hawkins)
Дата:
One:
su root
su - nobody
Cd to the appropriate directory.  Run the script.  What happens?

Two: (If that didn't help) Do the CGI magic to make the browser
display the environment variables set for the CGI script.  Su to
nobody (as above) and set all the env variables (and I mean all of
them, including HOME) the same as for the browser.

Run the script.  What happens?

Three: If you got a failure, then su to nobody, and set all the env
variables identically to those of the user (or situation) for which
the script works.  Run the script.

Four:  Change them one by one, running the script each time.

Modify algorithm as necessary as illumination strikes.  Take careful
notes.

Be wary of init files in home directories.

>>>>> "p" == pgsql-admin-digest  <owner-pgsql-admin-digest@hub.org> writes:

p> Date: Sun, 27 Feb 2000 17:27:29 -0700
p> From: Carla J Breuker <carlajb@juno.com>
p> Subject: Perl Script and Postgres DB running via Apache Web Server

p> Hi...

p> I have the following Perl Script (with Postgres code):

p>     #!/usr/bin/perl -w
p>     use Pg;

p>     print "<HTML><P>This is a test</HTML"

p>     $conn = Pg::connectdb("dbname=test");
p>     $conn->exec("insert into test_table values ('Carla', '90')");

p> This Script will run from the command line, and inserts values into the
p> existing DB and table.
p> When it is run via the web browser, nothing happens (browser hangs).

p> The script is in the /usr/local/httpd/cgi-bin directory, owned by a user
p> (not root), and has 755 permissions.

p> We have exhaustively searched perl, cgi, postgres, and apache
p> documentation both printed and web-based,
p> and cannot determine how to correct this problem.

p> We suspect that it may be a permissions / execution rights for the httpd,
p> but we are stumped.

p> Any help will be greatly appreciated.

p> Thanks,
p>     -Carla and Chris :)
p> ________________________________________________________________
p> YOU'RE PAYING TOO MUCH FOR THE INTERNET!
p> Juno now offers FREE Internet Access!
p> Try it today - there's no risk!  For your FREE software, visit:
p> http://dl.www.juno.com/get/tagj.

p> ------------------------------

p> End of pgsql-admin-digest V1 #463
p> *********************************


p> ************



Re: Perl Script and Postgres DB running via Apache Web Server

От
Mark Dalphin
Дата:
Hi Carla and Chris,

> I have the following Perl Script (with Postgres code):
>
> [ stuff deleted]

> This Script will run from the command line, and inserts values into the
> existing DB and table. When it is run via the web browser, nothing happens
> (browser hangs). The script is in the /usr/local/httpd/cgi-bin directory,
> owned by a user (not root), and has 755 permissions. We have exhaustively
> searched perl, cgi, postgres, and apache documentation both printed and
> web-based, and cannot determine how to correct this problem. We suspect that
> it may be a permissions / execution rights for the httpd, but we are stumped.
> Any help will be greatly appreciated. Thanks, -Carla and Chris :)

I suspect the problem is not "who owns the script", but rather "who runs the
script".  Usually your httpd runs as user "nobody", who also happens to have
very few permissions for anything on your system.  Meanwhile, your Postgres
database table was create by you and probably doesn't include permissions for
user "nobody" to even "SELECT" the table, much less modify it.

Guessing here, but you probably don't have a Postgres user named "nobody" (see
"createuser") nor have you granted permissions on any tables to user "nobody"
(see the SQL command "grant").  As user "nobody" usually has no login account
for security reasons, you may wish to experiment with permissions by using two
standard login accounts to see who can read what and when.

For what it is worth, I often find with this kind of problem (CGI scripts that
mis-behave especially when interacting with a database) that changing my httpd
logging "up" from a level of "warn" to "debug" and then reading both the httpd
log and the postgresql log file helps greatly in tracking down the problem.

Hope this helps,
Mark

--
Mark Dalphin                          email: mdalphin@amgen.com
Mail Stop: 29-2-A                     phone: +1-805-447-4951 (work)
One Amgen Center Drive                       +1-805-375-0680 (home)
Thousand Oaks, CA 91320                 fax: +1-805-499-9955 (work)