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

I've got a perl script that runs correctly when run by perl on the command line: sudo -u apache perl script.pl

However running the same script via a webbrowser produces different results - presubably as ModPerl is used.

The problem appears to perhaps be where the script is trying to read the contents of a local file - which fails via mod-perl.

Where do I start "porting" a script to ModPerl?

Thanks,

Replies are listed 'Best First'.
Re: ModPerl Compatibility
by derby (Abbot) on May 06, 2005 at 12:48 UTC

    Hmmm ... there's plenty of modperl info pages: perlmonks is not a replacement for google.

    Where's the code? Just running as the user apache doesn't necessarily mean it will run well under cgi or modperl. I can envision two scenarios as to why this is failing: 1, relative pathing - your pwd is not where you think it is; and 2, suexec is being used and apache isn't the effective user.

    But you forgot one very important piece of information -- how is the script failing (file doesn't exist, user doesn't have permissions)?

    -derby
Re: ModPerl Compatibility
by samizdat (Vicar) on May 06, 2005 at 12:36 UTC
    Are your filesystem permissions set properly to allow user 'apache' to write to the filesystem?
    • First test, make user apache a member of the group which owns local directory.
    • Second, make group permissions ('chmod g+x .') of local directory include x.
    • Make sure file permissions for group of file in question include 'r' ('chmod g+r filename')
    mod_perl should not require changes. It's most likely your permissions, second most likely your Apache httpd.conf setup. Third most likely is that you've mixed up http-accessed web directories from DocumentRoot with /-referenced UNIX local directories.
      mod_perl should not require changes
      This is almost completely not true. mod_perl is very different from running a command line perl script. As was mentioned in other responses your working directory may not be what you think it is, and depending on how apache is set up, it may even prevent you from doing a chdir().

      Not to mention that you are now running in a persistent environment where the difference between compile time and run time are even more significant. This will also magnify other problems in your code (globals, unintentional closures, etc) that would not show up otherwise.

      All of these issues are known and well documented and acceptable if you want the performance benefits of mod_perl. But to say that it shouldn't require any code changes is very misleading...

      And for the OP, you can read here for more info on begining your mod_perl life.