cPanel plugin with PHP code 500 error

Miguel G

Well-Known Member
Jun 4, 2015
86
0
6
Spain
cPanel Access Level
Root Administrator
Twitter
I have followed these instructions here:

How to create a Plugin (WHM & cPanel)

and here

cPanel Plugin File Generator - Version 68 Documentation - cPanel Documentation

I managed to get the .tar.gz file with:

Unique identifier: Wordpress_Staging
Name: Wordpress Staging
Group: Ibertrix (new group)
Priority: 99
URI: ibertrix/wpstaging/index.php
URI target: (empty)
Icon: a 48x48 png file

In index.php I put this code


Code:
<?php
include("/usr/local/cpanel/php/cpanel.php");  // Instantiate the CPANEL object.
$cpanel = new CPANEL();                       // Connect to cPanel - only do this once.
print $cpanel->header( "Page Heading" );      // Add the header.
?>
 
<?php
$get_userdata = $cpanel->uapi(                // Get domain user data.
    'DomainInfo', 'domains_data',
    array(
        'format'    => 'hash',
    )
);
?>
 
 <?php
print $cpanel->footer();                      // Add the footer.
$cpanel->end();                               // Disconnect from cPanel - only do this once.
?>
I get a 500 error. Where I can debug why is not working? /var/log/apache2/error_log doesn´t show anything

I forgot! I use version 68
 
Last edited by a moderator:

Miguel G

Well-Known Member
Jun 4, 2015
86
0
6
Spain
cPanel Access Level
Root Administrator
Twitter
I get this error:

Code:
PHP Fatal error:  Uncaught exception 'RuntimeException' with message 'There was a problem fetching the env variablecontaining the path to the socket' in /usr/local/cpanel/php/cpanel.php:146
Stack trace:
#0 /tmp/cpanel_phpengine.1535738975.31783VtVl8U9FBY(3): CPANEL->__construct()
#1 {main}
  thrown in /usr/local/cpanel/php/cpanel.php on line 146
 

cPanelLauren

Product Owner II
Staff member
Nov 14, 2017
13,266
1,304
363
Houston

cPanelLauren

Product Owner II
Staff member
Nov 14, 2017
13,266
1,304
363
Houston
Hi @Miguel G

My only suggestion would be to look at the code used for the plugin. I tested the installation steps which seem to work without issue. What it sounds like may not have been done was the second tar.gz:

Per the instructions here:
Code:
The compressed infection_scanner.tar.gz file should then be included with your backend code (your plugin/app) in another tar file (used for distribution).
 

Miguel G

Well-Known Member
Jun 4, 2015
86
0
6
Spain
cPanel Access Level
Root Administrator
Twitter
What do you mean with the second .tar.gz? I don´t quite get you.

I generate the .tar.gz and install it like this:

Code:
/usr/local/cpanel/scripts/install_plugin /var/cpanel/cpanel_plugin_generator/wpstaging.tar.gz
Any PHP sample code I can use? I just took a random PHP example I found on the internet. I was just testing how to create a PHP plugin, my idea is to have a form with three fields and pass them to a PHP script as parameters
 

cPanelLauren

Product Owner II
Staff member
Nov 14, 2017
13,266
1,304
363
Houston
Hi @Miguel G

That guide has a sample though it's written in perl the steps should be the same. If you look at the guide it notes that you need to include your code in another tar. This is detailed in Step 2:

Code:
Step 2: Create the install.json file.
To create the install.json file, we go to WHM => Development => cPanel Plugin File Generator. Documentation on how to use this can be found here:
cPanel Plugin File Generator - Documentation - cPanel Documentation

You'll need a Unique Identifier (letters, numbers, hyphens and underscores). For the purposes of this tutorial, I used "Infection_Scanner"

For the Name I used "Infection Scanner", the Group I selected "Security", for the Priority I chose "99" and for the URI, I entered: "infection_scanner/infection_scanner.live.pl".

You'll also need an icon that is 48px by 48px and must be in PNG format. Browse for your icon file and add it to the page.

Finally click the Add Item button and for the name (top-right) enter "infection_scanner".

This will create a compressed tar.gz file in /var/cpanel/cpanel_plugin_generator directory, called infection_scanner.tar.gz. The UI will also give you a chance to download the file.

The contents of the infection_scanner.tar.gz file will be an infection_scanner/ directory and within that directory will be an install.json file, a meta.json file (which only contains a timestamp and cpversion information), and your icon. The meta.json file is not required and if you wish, you can remove it from the archive, but it also does not hurt to leave it in place.

The contents of the install.json file will look something like this:

[{"icon":"infection_scanner.png","featuremanager":true,"name":"Infection Scanner","uri":"infection_scanner/infection_scanner.live.pl","group_id":"security","order":"99","type":"link","id":"infection_scanner"}]
The compressed infection_scanner.tar.gz file should then be included with your backend code (your plugin/app) in another tar file (used for distribution).
As I quoted earlier the full line is:

Code:
The compressed infection_scanner.tar.gz file should then be included with your backend code (your plugin/app) in another tar file (used for distribution).
 

cPanelLauren

Product Owner II
Staff member
Nov 14, 2017
13,266
1,304
363
Houston

Miguel G

Well-Known Member
Jun 4, 2015
86
0
6
Spain
cPanel Access Level
Root Administrator
Twitter
I even tried following this blog entry changing /usr/local/cpanel/base/frontend/ibertrix/wpstaging/index.php to

Code:
<html>
<pre>
<?php

include("/usr/local/cpanel/php/cpanel.php");


$cpanel = &new CPANEL();
print_r  ( $cpanel->exec('<cpanel print="cow">') );
print_r  ( $cpanel->api1('print','',array('cow')) );
print_r  ( $cpanel->exec('<cpanel setvar="debug=0">') );
print_r  ( $cpanel->api('exec',1,'print','',array('cow')) );
print_r  ( $cpanel->cpanelprint('$homedir') );
print_r  ( $cpanel->cpanelprint('$hasvalidshell') );
print_r  ( $cpanel->cpanelprint('$isreseller') );
print_r  ( $cpanel->cpanelprint('$isresellerlogin') );
print_r  ( $cpanel->exec('<cpanel Branding="file(local.css)">') );
print_r  ( $cpanel->exec('<cpanel Branding="image(ftpaccounts)">') );
print_r  ( $cpanel->api2('Email','listpopswithdisk',array('api2_paginate' => 1, 'api2_paginate_start' => 1, 'api2_paginate_size' => 10, "acct"=>1) ) ) ;
print_r  ( $cpanel->fetch('$CPDATA{\'DNS\'}') );
print_r  ( $cpanel->api2('Ftp','listftpwithdisk',array("skip_acct_types"=>'sub') ) );
print_r  ( $cpanel->uapi('SSL','list_keys', array( 'api.sort_column' => 'friendly_name' )));
print_r  ( $cpanel->uapi('non-exist','list_keys', array( 'api.sort_column' => 'friendly_name' )));
print_r  ( $cpanel->api3('SSL','list_certs', array( 'api.sort_column' => 'subject.commonName', 'api.filter_column' => 'modulus', 'api.filter_term'  => 'mod_goes_here' ,'api.sort_column' => 'friendly_name' )));print_r  ( $cpanel->api2(array('Ftp' => 1),'listftpwithdisk',array("skip_acct_types"=>'sub') ) ); // should complain about an untrappable failure

if ( $cpanel->cpanelif('$haspostgres') ) { print "Postgres is installed\n"; }if ( $cpanel->cpanelif('!$haspostgres') ) { print "Postgres is not installed\n"; }
if ($cpanel->cpanelfeature("fileman")) {
        print "The file manager feature is enabled\n";
}
print "test complete\n";
$cpanel->end();

?>
</pre></html>

but I get a blank page and this error:

Code:
PHP Fatal error:  Uncaught exception 'RuntimeException' with message 'There was a problem fetching the env variablecontaining the path to the socket' in /usr/local/cpanel/php/cpanel.php:146
Stack trace:
#0 /tmp/cpanel_phpengine.1535747270.279487IkUoFyQ7o(8): CPANEL->__construct()
#1 {main}
  thrown in /usr/local/cpanel/php/cpanel.php on line 146
 

Miguel G

Well-Known Member
Jun 4, 2015
86
0
6
Spain
cPanel Access Level
Root Administrator
Twitter

Miguel G

Well-Known Member
Jun 4, 2015
86
0
6
Spain
cPanel Access Level
Root Administrator
Twitter
A couple of things:

1.- Is it possible while developing the plugin to make it only accessible for one user account for testing?

2.- I am seeing that using PHP could be the worst thing to do since I have disabled exec in PHP. I just want to be able to select in a form as the Wordpress addon you provide in cpaddons the list of domains and subdomains created in the Cpanel account and call an external WP-CLI based bash script to create a site. Maybe is better to use those .tt html language you use?
 

cPanelLauren

Product Owner II
Staff member
Nov 14, 2017
13,266
1,304
363
Houston
Hi @Miguel G

1.- Is it possible while developing the plugin to make it only accessible for one user account for testing?
If you've added the plugin you should be able to disable it from all users by using the feature manager. Just have it enabled in the featurelist for the user you want to develop with.

2.- I am seeing that using PHP could be the worst thing to do since I have disabled exec in PHP. I just want to be able to select in a form as the Wordpress addon you provide in cpaddons the list of domains and subdomains created in the Cpanel account and call an external WP-CLI based bash script to create a site. Maybe is better to use those .tt html language you use?
Keep in mind cPanel's internal PHP is different than the site's PHP so configurations made to the PHP versions your sites use won't have an effect on the internal PHP. I believe as far as languages to write the plugin, in we recommend LivePHP