title: Perl IO::Socket::INET permission denied
body: <p>Have a perl script to connect with a Java service running on localhost, passes encrypted cookie, and returns decrypted data.  When I run script from command line, it works fine.  Even gave apache user a shell, and ran from command line as that user, which also works fine.  If the script is run as CGI from apache, the socket new returns undef and $! is set with "permission denied".  ???  </p>
  
  <p>Running CentOS 6.3 on this server, and IPtables are disabled.</p>
  
  <pre><code>#!/usr/bin/perl
  
  use strict;
  
  use CGI;
  use IO::Socket;
  use JSON;
  
  my $cgi = CGI-&gt;new();
  
  my $cookie = $cgi-&gt;cookie('attESSec') || shift (@ARGV) || undef;
  my $data = JSON::false;
  
  if($cookie){
    my $socket = IO::Socket::INET-&gt;new(
      'PeerHost' =&gt; '127.0.0.1',
      'PeerPort' =&gt; '1500',
      'Proto'    =&gt; 'tcp'
    );
    if($socket){
      $socket-&gt;send($cookie . "\r\n");
      $socket-&gt;recv(my $auth,1024);
      $socket-&gt;close();
      chomp($auth);
      if($auth){
        $data = (split(/\|/,$auth))[5];
      }
    }
    else{
      $data = $!;
    }
  }
  
  print($cgi-&gt;header('application/javascript'));
  print(JSON-&gt;new()-&gt;allow_nonref()-&gt;utf8()-&gt;encode($data));
  
  exit();
  </code></pre>