Wallogit.com
2017 © Pedro Peláez
Cpanel/WHM API for PHP
NOTE: This library is modified from original code of gufy/cpanel-php, (*2)
I rewrite runQuery() function to use cURL instead of GuzzleHttp, (*3)
To install this package, you can run this code via your terminal, (*4)
composer require fafan/cpanel-php
Or update your composer.json by adding this line, (*5)
"fafan/cpanel-php":"^0.1"
Then, run this code, (*6)
composer update
For example, if you would like to get list accounts of your whm server, you can do this., (*7)
<?php
$cpanel = new \Fafan\CpanelPhp\Cpanel([
'host' => 'https://123.456.789.123:2087', // ip or domain complete with its protocol and port
'username' => 'root', // username of your server, it usually root.
'auth_type' => 'hash', // set 'hash' or 'password'
'password' => 'password', // long hash or your user's password
]);
$accounts = $cpanel->listaccts(); // it will returned as array
This is the example when you want to define your configuration while creating new object, (*8)
<?php
$cpanel = new \Fafan\CpanelPhp\Cpanel([
'host' => 'https://123.456.789.123:2087', // required
'username' => 'root', // required
'auth_type' => 'hash', // optional, default 'hash'
'password' => 'password', // required
]);
Somehow, you want to override your current configuration. To do this, here is the code, (*9)
<?php // change username andd (password or hash) $cpanel->setAuthorization($username, $password); // change host $cpanel->setHost($host); // change authentication type $cpanel->setAuthType($auth_type);
After you define some of your configuration, you can get it again by calling this functions, (*10)
<?php // get username $cpanel->getUsername(); // get password $cpanel->getPassword(); // get authentication type $cpanel->getAuthType(); // get host $cpanel->getHost();
Original code: gufy/cpanel-php, version 1.0, (*11)
By Mochamad Gufron mgufronefendi@gmail.com, (*12)