This is the mail archive of the cygwin mailing list for the Cygwin project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Fix: Socket problem w/ apache & perl cgi (fwd)

A couple of months ago I reported a problem trying to use Apache and perl
for web development.  The problem was that all attempts to use any kind of
a socket failed.

I just got this note from Eric Davis.  He's worked out the problem and a

He asked me to forward this to the mailing list as he is not subscribed.


---------- Forwarded message ----------
Date: Wed, 6 Oct 2004 12:18:29 -0700
From: Eric Davis <>
Subject: Fix: Socket problem w/ apache & perl cgi

Hi David,

I came across your post on the Cygwin mailing list about Perl/CGI not
working under Apache.

Like you, I was also pulling my hair out on this and figured out the
problem/solution.  I verified that the problem exists and the solution
works for both the Apache and Boa web servers.

The following CGI script works from the bash prompt but fails as a
CGI program (name - proto_real.cgi):


  print "Content-Type: text/html\r\n\r\n<html>\n<head></head>\n<body>\n";

  my $num;
  (undef, undef, $num) = getprotobyname('tcp');

  if ($num)
      print "OK: tcp($num)<br/>\n";
      print "ERROR<br/>\n";

  print "</body>\n</html>\n";

The problem has to do with (good) Web servers removing all the existing
environment variables before a fork and exec of the CGI script, and of
course building new environment variables containing all the CGI data.
For some reason, Cygwin requires the SYSTEMROOT environment variable to
be set for things to work properly.

The fix (i.e. without modifying any Web server CGI code) is to create
a wrapper around the real script.  This wrapper simply sets the
SYSTEMROOT environment variable and executes the real script.  Here
is an example wrapper (name - proto.cgi):



  exec 'proto_real.cgi'

That should do it.  With this, I can now write CGI code using Apache
or Boa under the Cygwin environment.  So using DBI, DBD::mysql,
DBD::mysqlPP, IO::Socket, etc, now works as expected... all of which
I have used/tested under Cygwin/Apache/Perl/CGI.

Lastly, could you please post this as a reply to your original question
on the Cygwin mailing list.  I'm not on that list and don't want to
subscribe just to post this.

Good luck!

- eric

   Eric Davis

Unsubscribe info:
Problem reports:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]