Pergunta

I'm trying to develop a Web app in Perl using Hypertable. Sample code:

#!/usr/bin/perl -w
use strict;
use warnings;
use CGI;
use CGI::Carp qw/fatalsToBrowser warningsToBrowser/;
use CGI::Session ('-ip_match');
use Hypertable::ThriftClient;
use Data::Dumper;

my $q = new CGI;
print $q->header(-cache_control => "no-cache, no-store, must-revalidate");

eval {
    my $client    = new Hypertable::ThriftClient("localhost", 38080);
    my $namespace = $client->open_namespace("glinpe");
    my $result    = $client->hql_exec($namespace, "select * from words where row=\"maths\" keys_only");
};

if ($@) {
    if ($@->isa('Thrift::TException')) {
        print Dumper($@);
    } else {
        print Dumper($@);
    }
}
print "<h1>works</h1>";

The problem is when trying to execute from a web browser I get an error:

$VAR1 = bless( { 'code' => 0, 'message' => 'TSocket: Could not connect to localhost:38080 (Permission denied)' }, 'Thrift::TException' );

The scripts works properly when running from a terminal(under apache user), and as well in a browser if remove all Hypertable code.

I have 38080 port opened in iptables:

-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 38080 -j ACCEPT

OS: Centos 5.6.

Foi útil?

Solução 2

OK, so there is two solution to this particular problem: 1. disable selinux - change configuration in /etc/selinux/config 2. run command:

setsebool -P httpd_can_network_connect 1

Thanks to previous answer for putting me back on track.

Outras dicas

The error message says you're missing permission, so that would be the answer (user apache, doesn't have permission to create socket to localhost:38080)

update: to elaborate, when you run it from a terminal, it is running as a regular user, but when apache runs it, most often it is running under apache user account, which may not have permission to open sockets

It could be you're using SELinux in which case see 'man chcon' or search for "SELinux tutorial: Configuring RHEL 5 and Web servers"

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top