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

Dear Monks,

Happy New Year!

I have been using the GD.pm module (although this question applies to any such module) on my local server (WinXP, ActivePerl...PPM installation) for some time now and need to install it on my remote server. The remote server is linux and I do not have root access or telnet/command-line access. This obviously makes installing any perl module that requires compilation quite tricky.

I have been trying to use CPAN.pm through its programming interface as a possible solution. This is recommended from literature I have read but I can't seem to make it work.

Firstly, the literature:
http://search.cpan.org/~andk/CPAN-1.80/lib/CPAN.pm#FAQ - see point 5
http://sial.org/howto/perl/life-with-cpan/non-root/ - some more on this subject

I've tried to use this information but obviously it is designed for someone with command-line access.

My code:

1 #! /usr/bin/perl -w 2 3 use CPAN; 4 CPAN::Config='EDITED FOR SECURITY PURPOSES'; 5 6 print "Content-type: text/html\n\n"; 7 my $mod = 'GD'; 8 print "Working...<br>"; 9 10 my $obj = CPAN::Shell->expand('Module',$mod); 11 $obj->install; 12 print "<br>Finished";
In particular, line 4 seems dodgy. This is my reckoning of % echo '$CPAN::Config={ };' > $HOME/.cpan/CPAN/MyConfig.pm from the CPAN notes above. Note the absolute path.

Finally, the modified MyConfig.pm as explained in http://sial.org article. Again, my absolute paths feature, although I'm not sure if I've applied this correctly.

$CPAN::Config = { 'build_cache' => q[5], 'build_dir' => q[EDITED FOR SECURITY PURPOSES], 'cache_metadata' => q[1], 'cpan_home' => q[EDITED FOR SECURITY PURPOSES], 'dontload_hash' => { }, 'ftp' => q[/usr/bin/ftp], 'ftp_proxy' => q[], 'getcwd' => q[cwd], 'gzip' => q[/usr/bin/gzip], 'histfile' => q[EDITED FOR SECURITY PURPOSES], 'histsize' => q[100], 'http_proxy' => q[], 'inactivity_timeout' => q[0], 'index_expire' => q[1], 'inhibit_startup_message' => q[0], 'keep_source_where' => q[EDITED FOR SECURITY PURPOSES], 'lynx' => q[ ], 'make' => q[/usr/bin/make], 'make_arg' => q[], 'make_install_arg' => q[], 'makepl_arg' => q[PREFIX=~/ SITELIBEXP=~/lib/perl5 LIB=~/lib/perl5 I +NSTALLMAN1DIR=~/share/man/man1 INSTALLMAN3DIR=~/share/man/man3 INSTAL +LSITEMAN1DIR=~/share/man/man1 INSTALLSITEMAN3DIR=~/share/man/man3], 'ncftp' => q[ ], 'ncftpget' => q[ ], 'no_proxy' => q[], 'pager' => q[less], 'prerequisites_policy' => q[ask], 'proxy_user' => q[], 'scan_cache' => q[atstart], 'shell' => q[/bin/sh], 'tar' => q[/usr/bin/tar], 'term_is_latin' => q[0], 'unzip' => q[/usr/bin/unzip], 'urllist' => [q[http://cpan.llarian.net/], q[ftp://cpan.nas.nasa.gov +/pub/perl/CPAN/], q[ftp://cpan.pair.com/pub/CPAN/], q[ftp://ftp.duke. +edu/pub/perl/], q[ftp://ftp.cs.colorado.edu/pub/perl/CPAN/], q[ftp:// +ftp.sunsite.utk.edu/pub/CPAN/], q[http://www.perl.com/CPAN/]], 'wait_list' => [q[wait://ls6.informatik.uni-dortmund.de:1404]], 'wget' => q[/usr/bin/wget], }; 1; __END__

When I run my program, however, all I get is

Working... CPAN: Storable loaded ok
Checking to see if the GD module has been installed, I find that it has not.

Any assistance would be appreciated. Thanks!

Replies are listed 'Best First'.
Re: Remotely install modules
by randyk (Parson) on Jan 01, 2006 at 19:47 UTC

    I'm not sure CPAN.pm will understand line 4, specifying where your MyConfig.pm file is. Try removing this line, and simply put the MyConfig.pm file in your $HOME/.cpan/CPAN/ directory.

    A couple of other points to check:

    • sometimes CPAN.pm expects directories like INSTALLMAN3DIR=~/share/man/man3 to already exist, so you may have to initially create them.
    • you should verify that the paths to the specified programs, such as /usr/bin/make, are the correct ones. You may be able to just specify these by name (without the full path) if your PATH environment variable is appropriately set.

    UPDATE
    Another possibility you might check is that the user that the cgi script is running under may have a different HOME environment variable than you do. If that's the case, it may be easier to set the CPAN.pm config options directly in the script, as in the following:

    use CPAN; use strict; use warnings; $CPAN::Config = { 'build_cache' => q[10], 'build_dir' => q[/full/path/to/your/build/dir], # etc 'makepl_arg' => q[PREFIX=/full/path/to/wherever LIB=/full/path/to/lib/perl5 # etc ], # etc 'wget' => q[], }; $CPAN::Config_loaded = 1; my $mod = 'GD'; my $obj = CPAN::Shell->expand('Module',$mod); $obj->install;
    and verify that the appropriate permissions are in place to allow the script to install things in the specified locations.

Re: Remotely install modules
by indiansummersky (Beadle) on Jan 02, 2006 at 02:07 UTC
    Latest version (which works perfectly for modules like CPAN and Yahoo::Search) but is chucking up blood for GD.pm (although, I think, not due to my code):
    #! /usr/bin/perl -w use strict; use CGI; use CGI::Carp qw(fatalsToBrowser); use CPAN; use CPAN::Config; my $query = new CGI; my $update = $query->url_param('update'); my $moduleparam = $query->url_param('module'); if ($update) { for my $key (keys %{$CPAN::Config}) { $CPAN::Config->{$key} = $query->param($key) unless grep($key e +q $_, qw[dontload_hash urllist wait_list]); } } else { $CPAN::Config->{'build_dir'} = q[EDITED FOR SECURITY PURPOSES]; $CPAN::Config->{'cpan_home'} = q[EDITED FOR SECURITY PURPOSES]; $CPAN::Config->{'histfile'} = q[EDITED FOR SECURITY PURPOSES]; $CPAN::Config->{'keep_source_where'} = q[EDITED FOR SECURITY PURPO +SES]; $CPAN::Config->{'make_install_arg'} = q[]; $CPAN::Config->{'makepl_arg'} = q[PREFIX=EDITED FOR SECURITY PURPO +SES SITELIBEXP=EDITED FOR SECURITY PURPOSES LIB=EDITED FOR SECURITY P +URPOSES INSTALLMAN1DIR=EDITED FOR SECURITY PURPOSES INSTALLMAN3DIR=ED +ITED FOR SECURITY PURPOSES INSTALLSITEMAN1DIR=EDITED FOR SECURITY PUR +POSES INSTALLSITEMAN3DIR=EDITED FOR SECURITY PURPOSES]; } print $query->header(); printf '<h2>CGI CPAN Module Installer</h2><h3>CPAN Configuration (CPAN +::Config)</h3><form action="%s?update=1&module=%s" method="post"><tab +le border="0" cellpadding="3" cellspacing="0">', $query->url(-relativ +e=>1), $moduleparam; for my $key (sort keys %{$CPAN::Config}) { printf '<tr><td align="right"><label for="%s">%s</label></td><td>< +input type="text" name="%s" value="%s" size="75" /></td></tr>', $key, + $key, $key, $CPAN::Config->{$key} unless grep($key eq $_, qw[dontloa +d_hash urllist wait_list]); } print '<tr><td colspan="2" align="right"><input type="submit" value="r +un again" /></td></tr></table></form>'; if ($moduleparam) { print '<p /><h3>Working...</h3><textarea cols="76" rows="25">'; my $module = CPAN::Shell->expand('Module',$moduleparam); $module->install; print '</textarea><p />'; } print '<strong>finished</strong>';
      GD.pm requires the gd library to be installed - do you know if it's available in some standard location? Also, the perl Makefile.PL stage prompts the user for some information on how the library was compiled; for a non-interactive install, you should verify that that defaults are appropriate.
Re: Remotely install modules
by pboin (Deacon) on Jan 02, 2006 at 12:25 UTC

    I've found that many times, the very best thing to do in a case like this is to instantiate Human::Conversation and talk to the admin of the box. They might not have any problem, especially if you offer to help out.

    It pays to ask.