The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

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

Discussion in 'cPanel Developers' started by willcodeforfood, Aug 19, 2011.

  1. willcodeforfood

    willcodeforfood Registered

    Joined:
    Aug 18, 2011
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    1
    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. MattDees

    MattDees cPanel Product Owner
    Staff Member

    Joined:
    Apr 29, 2005
    Messages:
    417
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    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;
     
Loading...

Share This Page