Results 1 to 2 of 2

Thread: Possible to install additional perl modules for cpsrvd perl? (not system perl)

  1. #1
    Registered User
    Join Date
    Aug 2011
    Posts
    3

    Default Possible to install additional perl modules for cpsrvd perl? (not system perl)

    I'm writing a few cpanel api2 modules that are supposed to interact with a soap API. As far as I can tell, cPanel's web interface is using perl 5.6.2, and is missing a lot of the core modules that shipped with 5.6.2, and there is no XML parser or SOAP module of any sort(if this is incorrect, please point me in the right direction.)

    Is it possible to install additional perl modules for cpsrvd similar to the way that you can install modules for the perl installed for the system(the one Apache uses for CGI scripts.) I am able to use pure-perl modules, but any modules that have C based components have to be compiled against whatever perl interpreter they are going to be run on (as far as I know) and since the perl interpreter is built into the cpanel binary, I'm not sure how I would go about doing that.

  2. #2
    Member MattDees's Avatar
    Join Date
    Apr 2005
    Location
    Houston, TX
    Posts
    409

    Default Re: Possible to install additional perl modules for cpsrvd perl? (not system perl)

    This is possible, but this is not for the faint of heart.

    Within the cPanel & WHM ecosystem there is a way to add compiled modules - it is not documented for a reason. There is a script that exists on all cpanel systems at /usr/local/cpanel/build-tools/ called "buildperl" this will modify a Makefile.PL and run it so that it will install properly to cpsrvd's perl.

    For example, here's a script that will install XML::Parser (used in SOAP::Lite) to a cpanel system.

    note: this script may be buggy, this was done as a proof of concept. use at your own risk.

    Code:
    #!/usr/bin/perl
    # XML::Parser installer for cPanel
    # Tested with version 11.30.1
    
    use strict;
    use warnings;
    use File::Copy;
    use File::Copy::Recursive 'rcopy';
    use Cwd;
    
    use lib '/usr/local/cpanel';
    use Cpanel::SafeRun::Simple ();
    
    if ( !-e '/usr/local/cpanel/version' ) {
        die "this server does not have cPanel installed on it";
    }
    
    my $base = getcwd();
    chomp $base;
    my $cpperl = '/usr/local/cpanel/perl';
    my $arch = Cpanel::SafeRun::Simple::saferun('uname -i');
    chomp $arch;
    if ( $arch ne 'x86_64' ) {
        $arch = 'i686';
    }
    print "Copying the perl module 'English' into cPanel's perl environment\n";
    copy 'libs/English.pm', '/usr/local/cpanel/perl/English.pm';
    print "Copying the perl module 'Text::ParseWords' into cPanel's perl environment\n";
    copy 'libs/ParseWords.pm', '/usr/local/cpanel/perl/Text/ParseWords.pm';
    print "Extracting the XML::Parser v2.41 package\n";
    mkdir 'tmp';
    print Cpanel::SafeRun::Simple::saferun('tar vzxf libs/XML-Parser-2.41.tar.gz');
    if ( !-d 'XML-Parser-2.41') {
        print "XML Parser failed to extract. Installation cannnot continue\n";
        exit 1;
    }
    print "Copying File::Temp into the temporary location for XML::Parser usage\n";
    chdir 'XML-Parser-2.41';
    mkdir 'inc/File';
    copy "$base/libs/Temp.pm", 'inc/File/Temp.pm';
    print "Putting Config.pm into place\n";
    copy '/usr/local/cpanel/perl/' . $arch . '-linux/Config.pm', '/usr/lib/perl5/5.6.2/' . $arch . '-linux/Config.pm';
    print "Setting up ExtUtils in cPanel's perl environment\n";
    rcopy '/usr/local/cpanel/perl/ExtUtils/', '/usr/lib/perl5/5.6.2/ExtUtils/';
    
    copy '/usr/local/cpanel/perl/config.h', '/usr/local/cpanel/perl/x86_64-linux/CORE/';
    print "Running XML::Parser's Makefile.PL\n";
    print Cpanel::SafeRun::Simple::saferun('export ULCP=/usr/local/cpanel/perl; /usr/local/cpanel/build-tools/buildperl Makefile.PL SITEPREFIX=$ULCP PERL_LIB=$ULCP PERL_ARCHLIB=$ULCP/' . $arch . '-linux INSTALLPRIVLIB=$ULCP INSTALLSITELIB=$ULCP SITELIBEXP=$ULCP SITEARCHEXP=$ULCP/' . $arch . '-linux INSTALLARCHLIB=$ULCP/' . $arch . '-linux INSTALLMAN3DIR=/usr/local/cpanel/3rdparty/man');
    print "Running XML::Parser's `make`\n";
    print Cpanel::SafeRun::Simple::saferun('make');
    print "Running XML::Parser's `make install`\n";
    print Cpanel::SafeRun::Simple::saferun('make install');
    print "Complete!\n";
    chdir $base;
    Matt Dees

Similar Threads

  1. Installing additional Perl modules to help with module creation
    By higherlogic in forum cPanel Developers
    Replies: 1
    Last Post: 01-26-2011, 04:43 PM
  2. Cpanel Perl install overwrote CentOS Perl RPM?
    By dicen in forum cPanel & WHM Discussions
    Replies: 3
    Last Post: 01-31-2007, 01:40 PM
  3. Cant install any perl modules...
    By 4u123 in forum cPanel & WHM Discussions
    Replies: 6
    Last Post: 01-19-2006, 10:20 AM
  4. Replies: 0
    Last Post: 11-05-2003, 12:26 AM
  5. cannot install any perl modules
    By totalufo in forum cPanel & WHM Discussions
    Replies: 1
    Last Post: 04-15-2002, 02:39 PM