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

Hello All,

I'm trying to install Perl modules using CPAN.pm through a CGI script. FYI, I was able to install modules through the command line. Here, MyConfig.pm works as expected.

However, I'm aware that through the web, the script runs as user apache and looks for MyConfig.pm in apaches home directory. I don't have write access to apaches homedir, but I'm planning to install the modules inside a directory writeble to apache residing in my home directory.

What I've tried doing is modifying the Config hash inside the perl script like so:

use CPAN; use CPAN::Config; $CPAN::Config->{'build_dir'} = q[/home/rohan/.cpan/build]; $CPAN::Config->{'cpan_home'} = q[/home/rohan/.cpan]; $CPAN::Config->{'makepl_arg'} = q[PREFIX=/home/rohan/perllib LIB=/home +/rohan/perllib/lib/perl5];

Both, /home/rohan/.cpan and /home/rohan/perllib are writable by apache.

This does not seem to work. Any pointers will be very helpful.

Thanks for reading.

Replies are listed 'Best First'.
Re: using CPAN through web
by tlm (Prior) on Mar 29, 2005 at 22:02 UTC

    It would be helpful to know more about why this approach fails. What error messages do you get and where/when?

    the lowliest monk

      Hello,

      Here is the script:

      #!/usr/bin/perl use strict; use warnings; use CGI; use CPAN; use CPAN::Config; $CPAN::Config->{'build_dir'} = q[/home/rohan/.cpan/build]; $CPAN::Config->{'cpan_home'} = q[/home/rohan/.cpan]; $CPAN::Config->{'histfile'} = q[/home/rohan/.cpan/histfile]; $CPAN::Config->{'keep_source_where'} = q[/home/rohan/.cpan/sources]; $CPAN::Config->{'makepl_arg'} = q[PREFIX=/home/rohan/perllib LIB=home/ +rohan/perllib/lib/pe rl5]; my $q = CGI->new; print $q->header("text/plain"); CPAN::Shell->install("MP3::Tag");

      Both, /home/rohan/.cpan and /home/rohan/perllib are owned and writable by user apache.

      This is the output on the browser:

      CPAN: Storable loaded ok
      Going to read /home/rohan/.cpan2/Metadata
        Database was generated on Tue, 29 Mar 2005 09:53:28 GMT
      Running install for module MP3::Tag
      Running make for I/IL/ILYAZ/modules/MP3-Tag-0.94.tar.gz
      CPAN: Digest::MD5 loaded ok
      Checksum for /home/rohan/.cpan2/sources/authors/id/I/IL/ILYAZ/modules/MP3-Tag-0.94.tar.gz ok
      Scanning cache /home/rohan/.cpan2/build for sizes
      Uncompressed /home/rohan/.cpan2/sources/authors/id/I/IL/ILYAZ/modules/MP3-Tag-0.94.tar.gz successfully
      Using Tar:/bin/tar xvf /home/rohan/.cpan2/sources/authors/id/I/IL/ILYAZ/modules/MP3-Tag-0.94.tar:
      Couldn't untar /home/rohan/.cpan2/sources/authors/id/I/IL/ILYAZ/modules/MP3-Tag-0.94.tar
      <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
      <html><head>
      <title>200 OK</title>
      </head><body>
      

      OK

      The server encountered an internal error or misconfiguration and was unable to complete your request.

      Please contact the server administrator, root@localhost and inform them of the time the error occurred, and anything you might have done that may have caused the error.

      More information about this error may be available in the server error log.


      <address>Apache/2.0.52 (Fedora) Server at 127.0.0.1 Port 80</address> </body></html>

      As seen, I think the CPAN stuff gets initialized properly. All the necessary files are created in /home/rohan/.cpan. I guess there is some problem during the untar. I just can't seem to get it!

        The only thing I can think of is that /home/rohan/.cpan/build is not writable by apache, but from the description you gave in your original post it doesn't sound like that's the problem.

        the lowliest monk

Re: using CPAN through web
by brian_d_foy (Abbot) on Mar 30, 2005 at 03:50 UTC

    Why do you want to install modules through a CGI script? It looks like you have access to the server, so I don't see why you want to make things more complicated. Perhaps we could solve that problem and you can forget about your web troubles. :)

    --
    brian d foy <brian@stonehenge.com>

      I had shell access earlier. Thats how I managed to create a ".cpan" folder for myself :-)

      But no shell access now, and no help in installing Perl modules. Besides I've always wondered if there is a utility to install CPAN modules per-user through a web inerface so I thought I'd either roll my own or enquire around here.