DBD:Pg unable to connect as CGI process -- could not create socket

J

Jason

All of the cgi scripts I create to access postgres databases work from
the command line but do not work as CGI scripts. When accessed from a
browser the following line:

my $dbh =
DBI->connect( dbi:pg:dbname=$DatabaseName;host=localhost;port=5432;",
"postgres","mydog")

Produces the following error:
[Thu Jul 28 23:14:45 2005] [error] [client 207.161.60.253] DBI
connect('dbname=myRunningData;host=localhost;port=5432;' ,
'postgres',...) failed: could not create socket: Permission denied


I have tried to establish different identity rules for apache and have
ensured that the password for postgres is correct.

I am currently running Fedora Core 3 with

Postgresql 7.4.8-1.FC3.1
Apache 2.0.52-3.1
perl 5.8.5-14.FC3
DBD::pg 1.43

The lines below show my postgres config files.

Thanks in advance.

Jason


pg_hba.conf:

host all all 127.0.0.1 255.255.255.255
trust
local all all ident sameuser


postgresql.conf (relavant portions)

tcpip_socket = true
max_connections = 100
# note: increasing max_connections costs about 500 bytes of
shared
# memory per connection slot, in addition to costs from
shared_buffers
# and max_locks_per_transaction.
#superuser_reserved_connections = 2
port = 5432
#unix_socket_directory = ''
#unix_socket_group = ''
unix_socket_permissions = 0777 # octal
 
J

J. Gleixner

Jason said:
All of the cgi scripts I create to access postgres databases work from
the command line but do not work as CGI scripts. When accessed from a
browser the following line:

my $dbh =
DBI->connect( dbi:pg:dbname=$DatabaseName;host=localhost;port=5432;",
"postgres","mydog")

Produces the following error:
[Thu Jul 28 23:14:45 2005] [error] [client 207.161.60.253] DBI
connect('dbname=myRunningData;host=localhost;port=5432;' ,
'postgres',...) failed: could not create socket: Permission denied

I've never used PostgreSQL, however simply using Google and searching on
the error message, found the following:
http://sources.redhat.com/ml/cygwin/2004-09/msg01396.html

No idea what SYSTEMROOT is, but it sounds like the issue is with the
environment not being the same between the account that you use to run
it via the command line and the account that's running the Web server.
 
J

Jason

Unfortunately those articles are for cygwin and SYSTEMROOT is not a
factor for me.

However the difference between the apache account and is not clear to
me. I cannot su apache because I get:

This account is currently not available.

Any idea how I can run the script as apache and/or get a prompt as
apache?
 
J

J. Gleixner

Jason said:
Unfortunately those articles are for cygwin and SYSTEMROOT is not a
factor for me.

However the difference between the apache account and is not clear to
me. I cannot su apache because I get:

This account is currently not available.

Any idea how I can run the script as apache and/or get a prompt as
apache?

Yes, but you could see your Web server's ENVIRONMENT variables, by
running a CGI. e.g.

# cat /usr/local/www/cgi-bin/env.cgi
#!/usr/local/bin/perl
use CGI qw:)standard);
print header, start_html;
print li($_ . ' : ' . $ENV{$_}), "\n" for keys %ENV;
print end_html;

Actually, it'd be easier to just look at the ENVIRONMENT variables for
the account that works, and add the PostgreSQL related ones found in
that environemnt, to your CGI script.
 
J

Jason

Bill,

Thank you for pointing to that article. Unfortunately my problem is
more fundamental than PostgreSQL, and the information there did not fix
my problem.

I cannot get a socket connection via CGI at all. I opened my machine
to allow tcp finger requests and using the code from chapter 10.3 of
O'Rielly's CGI Programming and from
http://www.infocopter.com/perl/socket-server.htm I created a program
that returns the results of the finger command (see below).
From the command prompt the perl script creates the socket and gets the
result. *As a cgi program it cannot create a socket*. This could be
an issue for an apache group but I figured perl-cgi programmers would
recognize my symptoms more easily.

Thanks Jason

finger.cgi program:

#!/usr/bin/perl -w

use strict;
use Socket;
use CGI::pretty;

sub page {
my ($q, $title, $content) = @_;
print $q->header(), $q->start_html("$title");
print $q->h2("$title"), $q->p("$content"), $q->end_html();
exit;
}

my $q = new CGI::pretty();


# initialize protocol, host and port
my $proto = getprotobyname('tcp');
my $host = 'localhost';
my $port = getservbyname('finger','tcp');

# get the host internet address and port address
my $iaddr = inet_aton($host);
my $paddr = sockaddr_in($port, $iaddr);

# create the socket, connect to the port
socket(my $SOCKET, PF_INET, SOCK_STREAM, $proto) or &page($q , "Error",
"Socket: $!.\n");
connect($SOCKET, $paddr) or &page($q , "Error", "connect: $!");

#get reply from socket
my $result = "";
my $line;
while ($line = <$SOCKET>) {
$line = $q->escapeHTML($line);
$result .= $q->p($line);
}
close ($SOCKET);

#output reply from socket
&page($q, "No Errors!", $result);
 

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,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top