on 04-07-2010 8:29 PM
Thanks to I'm now making fine progress in getting perl to interact with my SAP system using sapnwrfc. However, I want to also write some scripts using CGI perl (or mod_perl) with Apache. I am avoiding using PHP because we already have other admins who are using Perl for other things.
I'm having problems getting the script to run under Apache. It runs fine from a command-prompt.
I first ran into LD_LIBRARY_PATH problems so that the library wasn't found. I fixed that so that I am now getting the modules to load (and the nwrfc libraries) but all I get when I run the script from my browser is the following in my error_log:
[Wed Apr 07 14:09:41 2010] [error] [client XXX.XXX.XXX.XXX] terminate called after throwing an instance of '
[Wed Apr 07 14:09:41 2010] [error] [client XXX.XXX.XXX.XXX] RfcInvalidParameterException
[Wed Apr 07 14:09:41 2010] [error] [client XXX.XXX.XXX.XXX] '
[Wed Apr 07 14:09:41 2010] [error] [client XXX.XXX.XXX.XXX] Premature end of script headers: rfcdest.cgi
My code is:
#!/usr/bin/perl
use lib qw(/usr/local/lib/perl5/ /usr/local/lib/perl5/site_perl);
use CGI qw /:standard/;
use strict;
use sapnwrfc;
use Getopt::Std;
use Data::Dumper;
print header();
print "testing4\n";
exit;
I know it is related to sapnwrfc because when I comment out the line
# use sapnwrfc;
the script works fine from my browser AND the command-line.
Can anyone help me with this? Has anyone else built sapnwrfc Perl scripts to run under Apache?
Yes - this does work with apache2, and I've just tested your script and it works fine for me (I modified the library paths to point to my build).
Make sure that all the libraries can be found and loaded at runtime by the user that is running apache. With Linux, I have added the paths to these to the ld cache (/etc/ld.so.conf + run ldconfig).
sapnwrfc for Perl is run in a number of production sites - including one that runs at about 400 pricing calls/sec (it's maxing out their CRM pricing module), so I think it's safe to say that it is production hardened.
Cheers,
Piers Harding.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
When you say you fixed the LD_LIBRARY_PATH issue, does that mean that you added /usr/sap/nwrfcsdk/lib (or equivalent) to the LD_LIBRARY_PATH for the Apache user, and restarted Apache?
Cheers,
David.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Long story short, I do set LD_LIBRARY_PATH (and I've tried /etc/ld.so.conf) and tried restarting with many different ways of setting the LD_LIBRARY_PATH. And I get a different error message when I don't have it set (implying that it can't find the nwrfcsdk libraries). So, I think I'm past that.
Now, here's something REALLY weird that I just discovered, which tells me it is not a module problem at all.
- My script runs fine from the command-line as a non-root user and as root user.
- My script does not run from the web server (which is what this thread is about).
- When I try to run /usr/local/nwrfcsdk/bin/rfcexec as root, it runs fine.
- When I try to run /usr/local/nwrfcsdk/bin/rfcexec as a normal user, I get the SAME MESSAGE:
terminate called after throwing an instance of 'RfcInvalidParameterException'
Abort
I also have this library installed in my home directory, and when I run the rfcexec program with either root or normal user it works fine!!
Oy, now I'm even more confused! Anyone have any idea about that (sorry, I know I'm getting beyond the scope of this subforum, but I thought I'd ask)
Edited by: Eric Young on Apr 7, 2010 10:58 PM
Hi -
This sounds like a permissions problem or an environment one, now.
Check the permissions on all the files/libs and directories in between when running the script (or rfcexec).
Check what the differences are in the environment between the root user and your other account - there maybe something there.
lastly - strace can help here, as it can show you when a file couldnt be found/opened - pointing to permissions/privileges problems.
Cheers.
OK, something is weird with either my config or NWRFCSDK.
NWRFCSDK Version: 711 (NWRFC_6-20004547.SAR)
Redhat: Red Hat Enterprise Linux ES release 4 (Nahant Update 6)
Here's a little experiment I ran:
chmod -R 777 /usr/local/nwrfcsdk/
- /usr/local/nwrfcsdk/bin/rfcexec by root works fine, normal user works fine
- web script still gives error RfcInvalidParameterException
chmod -R 755 /usr/local/nwrfcsdk/
- /usr/local/nwrfcsdk/bin/rfcexec by root works fine, normal user gives the error message: RfcInvalidParameterException
- web script gives error RfcInvalidParameterException
So, I wondered, does the nwrfcsdk write to the it's own directory!?
I followed your advice and strace'd rfcexec as a normal user. It was trying to check R/W access to "." ( access(".", R_OK|W_OK) ). Once the normal user can write to ".", it works. It doesn't appear to use it in any kind of file op *to access "." * after that.
I then changed the directory that my web script is in to mode 777 and IT WORKED!
This however, is kind of bad from a security stand point. Any advice on where to take this? I mean, it's not a script problem and not a sapnwrfc module problem, but who needs to know about this?
Edited by: Eric Young on Apr 7, 2010 11:58 PM
That's very strange, and I can't recreate your issue. I tried creating a temp directory, taking away my write access to it and running from there, and it makes no difference for me... everything still works. And strace does not check for any access to "." when I run it on rfcexec.
Do you have another system you can validate this from? I'm on RHEL 5.4 (Tikanga), just for the record. I don't have a RHEL 4 system I can test from.
Cheers,
David.
David, I tried on some other systems with the same results. My ability to test other configs is limited. I suspect my problem comes from our environmental config. I have a strong suspicion that it is related to our use of Vintella though I'm not smart enough to prove it. All I know is that the strace is doing a LOT of things before it even begins to do things that look like running the program rfcexec (including spawning child processes) It's been too long since I was a hardcore sys admin for me to be able to understand for sure.
Thank you Piers and David for working with me on this. I appreciate you going above and beyond just Perl module concerns to help me out. I understand if you don't want to spend any more time on this.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.