Loading ...
Sorry, an error occurred while loading the content.
 

Re: Working directory: CGI vs. mod_perl

Expand Messages
  • Tom Schindl
    ... Hash: SHA1 In Apache 1.3 this has been done by mp automatically when executing under PerlRun or Registry but because of the oulined problems this is not
    Message 1 of 8 , Aug 1, 2005
      -----BEGIN PGP SIGNED MESSAGE-----
      Hash: SHA1

      In Apache 1.3 this has been done by mp automatically when executing
      under PerlRun or Registry but because of the oulined problems this is
      not possible any more at least when supporting all mpms.

      If you are running on prefork and your cgi must be able to run as
      Apache::Registry and CGI you could register e.g. a TransHandler which
      looks like the following:

      - ----------------------------8<----------------------------
      package Util::FixUpDirectory;

      use Apache2::RequestUtil();
      use Apache2::Const();
      use Apache2::MPM ();

      sub handler {
      my $r = shift;

      if( ! Apache2::MPM->is_threaded ) {
      chdir $r->document_root();
      } else {
      print STDERR "Could not change to doc-root because you are
      running in a threaded mpm";
      }

      return Apache2::Const::OK;
      }
      - ----------------------------8<----------------------------

      - ----------------------------8<----------------------------

      <Directory /perl>
      SetHandler perl-script
      PerlTransHandler Util::FixUpDirectory
      PerlResponseHandler ModPerl::Registry
      Options +ExecCGI
      </Directory>
      - ----------------------------8<----------------------------

      I'm uncertain if one should also write a clean-up handler which sets the
      directory back to "/" or does Apache starts every request at "/"?

      Tom

      Jan Eden schrieb:
      > Hi Tom,
      >
      > Tom Schindl wrote on 01.08.2005:
      >
      >
      >>-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
      >>
      >>If you are running mp2 that's true simply because of the fact that
      >>chdir in perl is not thread-safe :-(
      >>
      >>If you are running in prefork(which is only available on *nix) you
      >>could chdir yourself at the top of your handler.
      >>
      >
      >
      > That's what I feared: There is really no way to determine the working directory in the mod_perl 2 configuration phase.
      >
      > Thanks,
      >
      > Jan

      -----BEGIN PGP SIGNATURE-----
      Version: GnuPG v1.4.0 (GNU/Linux)
      Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

      iD8DBQFC7iU2kVPeOFLgZFIRAtjsAJ0VNUwuUnnUGP7R2/VUGW4bl1ILnACeNbR/
      x/De7dfNcbOt9ArLmyGf4t0=
      =9mLd
      -----END PGP SIGNATURE-----
    • Philip M. Gollucci
      ... http://perl.apache.org/docs/2.0/user/porting/compat.html#C_Apache__Registry___C_Apache__PerlRun__and_Friends As it will say, use ModPerl::RegistryPrefork
      Message 2 of 8 , Aug 1, 2005
        > Jan Eden schrieb:
        >
        >>Hi,
        >>
        >>I just noticed that the working directory for scripts executed via a mod_perl handler is /.
        >>
        >>Is there a way to change that? Some of the scripts I use rely on the directory they are stored in is the current working directory.
        http://perl.apache.org/docs/2.0/user/porting/compat.html#C_Apache__Registry___C_Apache__PerlRun__and_Friends

        As it will say, use

        ModPerl::RegistryPrefork or ModPerl::PerlRunPrefork.
      • Jan Eden
        ... Thanks for the hint - but Apache fails to resolve the handler, although ModPerl::RegistryPreFork is right there: [Wed Aug 03 10:09:15 2005] [notice]
        Message 3 of 8 , Aug 3, 2005
          Philip M. Gollucci wrote on 01.08.2005:

          >>Jan Eden schrieb:
          >>
          >>>Hi,
          >>>
          >>>I just noticed that the working directory for scripts executed via
          >>>a mod_perl handler is /.
          >>>
          >>>Is there a way to change that? Some of the scripts I use rely on
          >>>the directory they are stored in is the current working directory.
          >http://perl.apache.org/docs/2.0/user/porting/compat.html#
          >C_Apache__Registry___C_Apache__PerlRun__and_Friends
          >
          >As it will say, use
          >
          >ModPerl::RegistryPrefork or ModPerl::PerlRunPrefork.
          >
          Thanks for the hint - but Apache fails to resolve the handler, although ModPerl::RegistryPreFork is right there:

          [Wed Aug 03 10:09:15 2005] [notice] Apache/2.0.53 (Unix) DAV/2 PHP/5.0.1 mod_perl/2.0.1 Perl/v5.8.1 configured -- resuming normal operations
          failed to resolve handler ModPerl::RegistryPreFork
          [jan:/usr/local/apache2/conf] ../bin/httpd -V
          Server version: Apache/2.0.53
          Server built: Mar 2 2005 15:11:13
          Server's Module Magic Number: 20020903:9
          Architecture: 32-bit
          Server compiled with....
          -D APACHE_MPM_DIR="server/mpm/prefork"
          [...]
          [jan:/usr/local/apache2/conf] locate RegistryPrefork
          /Library/Perl/5.8.1/darwin-thread-multi-2level/ModPerl/RegistryPrefork.pm
          /man/man3/ModPerl::RegistryPrefork.3pm

          In my mod_perl.conf, I have

          Alias /perl/ /Users/jan/Sites/janeden/perl/
          PerlModule ModPerl::RegistryPreFork
          PerlModule Apache::DBI DBI CGI

          <Location /perl>
          SetHandler perl-script
          PerlResponseHandler ModPerl::RegistryPreFork
          # PerlResponseHandler ModPerl::Registry
          PerlOptions +ParseHeaders
          Options +ExecCGI
          </Location>

          What is going wrong here?

          Thanks,

          Jan
          --
          Alcohol and calculus don't mix - PLEASE don't drink and derive.
        • Philippe M. Chiasson
          ... Case sensitivity issue here ^^^^^^^^ it s ModPerl::RegistryPerfork, lower case f -- Philippe M. Chiasson
          Message 4 of 8 , Aug 3, 2005
            Jan Eden wrote:
            > Philip M. Gollucci wrote on 01.08.2005:
            >>>Jan Eden schrieb:
            >> [...]
            >>
            >>As it will say, use
            >>
            >>ModPerl::RegistryPrefork or ModPerl::PerlRunPrefork.
            >>
            > Thanks for the hint - but Apache fails to resolve the handler, although ModPerl::RegistryPreFork is right there:
            >
            > [Wed Aug 03 10:09:15 2005] [notice] Apache/2.0.53 (Unix) DAV/2 PHP/5.0.1 mod_perl/2.0.1 Perl/v5.8.1 configured -- resuming normal operations
            > failed to resolve handler ModPerl::RegistryPreFork
            > [...]
            >
            > In my mod_perl.conf, I have
            >
            > [...]
            > <Location /perl>
            > SetHandler perl-script
            > PerlResponseHandler ModPerl::RegistryPreFork

            Case sensitivity issue here ^^^^^^^^
            it's ModPerl::RegistryPerfork, lower case f

            --
            Philippe M. Chiasson m/gozer\@(apache|cpan|ectoplasm)\.org/ GPG KeyID : 88C3A5A5
            http://gozer.ectoplasm.org/ F9BF E0C2 480E 7680 1AE5 3631 CB32 A107 88C3A5A5
          • Jan Eden
            ... If this is not embarrassing, nothing is. Thanks! - Jan -- I used to have a Heisenbergmobile. Every time I looked at the speedometer, I got lost.
            Message 5 of 8 , Aug 4, 2005
              Philippe M. Chiasson wrote on 03.08.2005:

              >Jan Eden wrote:

              >>[...] <Location /perl> SetHandler perl-script PerlResponseHandler
              >>ModPerl::RegistryPreFork
              >
              >Case sensitivity issue here ^^^^^^^^ it's
              >ModPerl::RegistryPerfork, lower case f

              If this is not embarrassing, nothing is.

              Thanks!

              - Jan
              --
              I used to have a Heisenbergmobile. Every time I looked at the speedometer, I got lost.
            Your message has been successfully submitted and would be delivered to recipients shortly.