cancel
Showing results for 
Search instead for 
Did you mean: 

Perl sapnwrfc: using it with Apache

EYoung
Explorer
0 Kudos

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?

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

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.

Answers (1)

Answers (1)

Former Member
0 Kudos

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.

EYoung
Explorer
0 Kudos

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

Former Member
0 Kudos

I can't seem to recreate your error no matter what I try.

What OS/version are you running on? And what is the version of the rfcsdk?

Cheers,

David.

Former Member
0 Kudos

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.

EYoung
Explorer
0 Kudos

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

Former Member
0 Kudos

Hmm - that's interesting. I haven't seen that behaviour at all.

You could try changing the current working directory, before the use sapnwrfc; statement to /tmp/ - that might fix it - please try , and let me know.

chdir('/tmp');

Cheers.

EYoung
Explorer
0 Kudos

Tried the chdir(/tmp) on a line before the use sapnwrfc.

I got the same error.

Checked again, chmod'ing the web directory to 777 fixes the problem, chmod'ing back to 755 breaks it.

Former Member
0 Kudos

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.

EYoung
Explorer
0 Kudos

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.

Former Member
0 Kudos

Eric, I assume this is a test box - I don't know the product, but is it possible to get an admin to temporarily disable Vintela to allow you to test that scenario?

Cheers,

David.

EYoung
Explorer
0 Kudos

I'm looking for a way to do that but I don't think it will happen quickly....

EYoung
Explorer
0 Kudos

FYI, remembering the order of how things happen for use & require, I tried the chdir("/tmp") and then did a "require" of sapnwrfc rather than a "use" and this solution worked.

Former Member
0 Kudos

Good point.

You could also try a BEGIN block for the chdur() - that way you should still be able to use "use", which will preserve specialised import code. eg:

BEGIN { chdir('/tmp'); };

use sapnwrfc;

Cheers.

Former Member
0 Kudos

That's great that you got it working!

Cheers,

David.