gbizeau has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

I have written the start of a script to talk to a PBX through Device::SerialPort

#!/usr/bin/perl -w

use warnings;
use strict;

use Device::SerialPort;
use CGI;

my $pbx = Device::SerialPort->new("/dev/ttyS0", baudrate => 2400, parity => "none", databits => 8, stopbits => 1, handshake => "none");

$pbx->write_settings() || die "failed write settings";


This is only the relevant snippit

This works fine when run from the command line, however when called as a CGI from Apache I get.

Can't call method "write_settings" on an undefined value at /var/www/cgi-bin/pbx.pl line 12.

This makes no sense to me, If I leave out the calls to Device::SerialPort, I get my web formated page properly, put it in, I get errors.

Run it from the command line, and I get the output I am looking for...No Errors!

I have never had this sort of issue with any Module in the past when using it as a web based program.

Help Please...

Glen

Replies are listed 'Best First'.
Re: Wierd Apache issue
by almut (Canon) on Sep 11, 2009 at 17:13 UTC

    My guess would be that the user the webserver runs under (often www-data) has no permissions to access /dev/ttyS0  (so the call to Device::SerialPort->new(...) fails and $pbx is undefined).

    For example, on my system, /dev/ttyS0  is

    $ ls -l /dev/ttyS0 crw-rw---- 1 root dialout 4, 64 2009-09-06 04:09 /dev/ttyS0

    and Apache (www-data) is not in group dialout (by default).

      Almut,

      Your a genius...

      I never even thought of that, I added apache to the uucp group, as it all stands on CentOS 5.3 and now it's working like a charm!!!

      TY TY TY TY TY