Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

script working from shell, but not from browser.

46 views
Skip to first unread message

sima...@gmail.com

unread,
Dec 18, 2009, 6:46:56 PM12/18/09
to beginn...@perl.org
so, i got some script with LWP and CGI using.
When run this script from shell - everything is ok, i got response
with data i need from the site.
But, when i run this script from browser i get error 500 -> "Can't
connect to www.something.com:80 (connect: Permission denied)".
I can`t understand how can it be... working from shell, but same
script not working from browser. Maybe there is some problem with
apache, but i can`t find it - the error_log is clean.

i try to search the Internet but find nothing to solve this problem,
so i decided to write here.

David Taiaroa

unread,
Dec 18, 2009, 9:02:56 PM12/18/09
to sima...@gmail.com, beginn...@perl.org
Hi,

When you run a script from shell it's probably as user 'you'.

When the script runs from a browser, it will be as user 'www' or something similar, with restricted permissions. Your shell user will have more permissions, so you might want to look at file permissions.

Also, you want to check the paths to any files referenced by the script. When runing a script as shell, you can probably access any file on the server, but user 'www' won't be able to.

If you haven't already done this, try something like:
perl -cw script-name.pl
and see if it gives any more info

Good luck!

Dave

Panchroma website development
www.panchroma.ca

> --
> To unsubscribe, e-mail: beginners-cg...@perl.org
> For additional commands, e-mail: beginners...@perl.org
> http://learn.perl.org/
>
>

Alexander Simashin

unread,
Dec 19, 2009, 2:18:24 AM12/19/09
to David Taiaroa, beginn...@perl.org
2009/12/19 David Taiaroa

>
> When you run a script from shell it's probably as user 'you'.
> When the script runs from a browser, it will be as user 'www' or something
> similar, with restricted permissions. Your shell user will have more
> permissions, so you might want to look at file permissions.
>

Of course , it is running under user apache. But i made all chmod and chown
what need, i think.

Also, you want to check the paths to any files referenced by the script.
> When runing a script as shell, you can probably access any file on the
> server, but user 'www' won't be able to.
>

This is okay too, the script only reads config file which has the right
permissions.
I try to exec script from apache user from shell, after making "su -l apache
-s /bin/bash" in console, and it ran perfect... But again - from browser we
got an error.

If you haven't already done this, try something like:
> perl -cw script-name.pl
> and see if it gives any more info
>

This gives me - "syntax OK"

Alexander Simashin

unread,
Dec 19, 2009, 3:39:04 AM12/19/09
to David Taiaroa, beginn...@perl.org
So it is time for an easy example script.
i wrote this little example maybe it will be clearly describe my problem. I
did not use any files or something for no more possible problems with
permissions.
*#!/usr/bin/perl
use CGI ;
use strict;
use warnings;
use Data::Dumper;
use CGI::Carp 'fatalsToBrowser';
use HTTP::Request::Common;
use vars qw($ua $h1 $response $req1 $suc $query);
use LWP::UserAgent;

$ua = new LWP::UserAgent;
$query = new CGI;# CGI
print $query->header;
$h1 = new HTTP::Headers;
$req1 = new HTTP::Request ('GET', 'http://www.cpan.org', $h1);
$response=$ua->request($req1);
print Dumper($response);
print $query->end_html;

*
So, when i run this from shell everything is okay and i get cpan.org page,
but from browser it gives Can\'t connect to www.cpan.org:80 (connect:
Permission denied.
You can see this result here http://62.176.11.182:50235/cgi-bin/test1.cgi
(test1.cgi is right the script above).
The problem seems really be in apache or httpd.conf or in CGI , but i can`t
understand where.
*
*

alexander simashin

unread,
Dec 20, 2009, 3:11:29 AM12/20/09
to David Taiaroa, beginn...@perl.org
>
> Hi Alexander,
>
> Since both scripts work on our server, and not yours, all I can think of is
> that it's something specific to your server environment.
>
I think that too, but can`t understand where is the problem :(.

2009/12/19 David Taiaroa <des...@panchroma.ca>

> Does something simple like this work for you? I'm trying to help you narrow
> down where the problem is.
>
> #!/usr/bin/perl
> use CGI ;


> $query = new CGI;# CGI
> print $query->header;
>

> my $url = 'http://www.cpan.org';
> use LWP::Simple;
> my $content = get $url;
> print $content;
>
> print $query->end_html;
>
>
> I have it at http://joiedevivre.nb.ca/cgi-bin/test3.cgi
>
>
> Dave
>
> ok. i modify it a little - i added some strings to print something before
and after print $content;
so now i have
print "before print \$content <br>";
print $content;
print "after print \$content <br> ";

so in shell it is works great, in browser we got -
before print $content
after print $content
... so the $content is empty.
http://62.176.11.182:50235/cgi-bin/test3.cgi

P.S. sorry but this is my home VMware server so it could be down for some
time.

Alexander Simashin

unread,
Dec 21, 2009, 3:07:37 AM12/21/09
to David Taiaroa, beginn...@perl.org
2009/12/21 David Taiaroa <des...@panchroma.ca>

> Hi Alexander,
>
> Is the LWP module in the same directory as the CGI module, and does it have
> permissions 644?
>
Yes, folders CGI and LWP are in /usr/lib/perl5/vendor_perl/5.10.0 and
permissions are 644.

Alexander Simashin

unread,
Dec 21, 2009, 3:42:26 AM12/21/09
to David Taiaroa, beginn...@perl.org
The problem solved now.
It is again(for me) selinux. When i disabled it - all began to work fine.
It is freaking me out at work, when we began to install linuxe`s with kernel
version 2.6(selinux was built in kernel from 2.6) or more i had big problems
with this new software...

> It drives me crazy, when you got working scripts, you just update linux
version and nothing working... you search the problem everywhere and killing
your brain for days... But somehow in someday you realize that maybe it is
stupid selinux again, and ohhhhhh!!!! it was really it...
I think all developers and system administrator who came from old great
working systems(with lower than 2.6 kernel) to new systems with 2.6 had same
problems, but this is future and now all linux distribution has selinux...
P.S. I just need to read more about it and try to understand how it is
working, instead of disabling it every time :)))). But this lost time of
crushing brain because of selinux again is driving crazy... really.
P.S. thanks for help and tries to solve the problem

0 new messages