Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > DBD:Pg unable to connect as CGI process -- could not create socket

Reply
Thread Tools

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

 
 
Jason
Guest
Posts: n/a
 
      07-29-2005
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( dbig:dbname=$DatabaseName;host=localhost;port=54 32;",
"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:g 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

 
Reply With Quote
 
 
 
 
J. Gleixner
Guest
Posts: n/a
 
      07-29-2005
Jason wrote:
> 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( dbig:dbname=$DatabaseName;host=localhost;port=54 32;",
> "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/.../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.
 
Reply With Quote
 
 
 
 
Jason
Guest
Posts: n/a
 
      07-29-2005
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?

 
Reply With Quote
 
J. Gleixner
Guest
Posts: n/a
 
      07-29-2005
Jason wrote:
> 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.

 
Reply With Quote
 
Jason
Guest
Posts: n/a
 
      08-01-2005
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:retty;

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:retty();


# 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);

 
Reply With Quote
 
Jason
Guest
Posts: n/a
 
      08-01-2005
Thanks Bill I will move the query to the suggested location.

Jason

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Could C each other, but could not connect vijaiakumar@gmail.com Computer Support 3 06-25-2007 05:00 AM
The underlying connection was closed: Unable to connect to the remote server. (Could not find the anwere in the groups) Christina ASP .Net Web Services 3 05-22-2006 09:39 PM
(CGI-Target)Could not connect to CGI-Proxy John Smith Java 0 05-15-2006 09:21 PM
Could not connect to mail server System.Web Could not access 'CDO.Message' object. ????? Adam Knight ASP .Net 1 12-05-2005 05:38 AM
Could Not Connect To SMTP Host Connection Failed -- Software caused connection abort: connect kishore@novelteam.com Java 3 11-16-2005 03:33 PM



Advertisments