- PHP 100%
These LithiumHosting/* packages are standalone Laravel libraries licensed under MIT, not LiBilling-specific components. The "LiBilling is (C) Lithium Holdings..." preamble belongs only on LiBilling/* integration packages. Strip the preamble; keep the per-package MIT attribution line. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> |
||
|---|---|---|
| config | ||
| src | ||
| .gitignore | ||
| CHANGELOG.md | ||
| composer.json | ||
| CONTRIBUTING.md | ||
| LICENSE.md | ||
| README.md | ||
LiBilling cPanel/WHM API Client
A typed PHP client for the cPanel/WHM JSON API, designed for billing system integrations. Provides explicit shortcut methods for all common WHM operations with proper error handling and IDE autocompletion.
Features
- WHM API 1: All server-level operations (account lifecycle, packages, SSO, usage)
- cPanel UAPI: User-level functions via WHM proxy (email management, etc.)
- Typed Shortcuts: Named methods for every billing-critical API call
- Custom Exception:
CpanelApiExceptionfor structured error handling - Reusable HTTP Client: Guzzle client created once, supports keep-alive
- Configurable SSL: Verify SSL on/off via config
Installation
This package is loaded as a local Composer path repository. No separate installation is needed when developing within the LiBilling monorepo.
For standalone installation:
composer require lithiumhosting/laravel-cpanel-api
Configuration
Publish the config file:
php artisan vendor:publish --tag=laravel-cpanel-api
Config Options
| Key | Env | Default | Description |
|---|---|---|---|
timeout |
CPANEL_API_TIMEOUT |
10 |
Request timeout in seconds |
connect_timeout |
CPANEL_API_CONNECT_TIMEOUT |
2 |
Connection timeout in seconds |
verify_ssl |
CPANEL_VERIFY_SSL |
true |
Verify SSL certificates |
Usage
use LithiumHosting\CpanelApi\CpanelApi;
$client = new CpanelApi([
'host' => 'https://svr1.example.com:2087',
'username' => 'root',
'password' => 'your-api-token',
'auth_type' => 'hash',
'verify_ssl' => true,
]);
// Account lifecycle
$client->createAccount('example.com', 'exampleu', 'password123', 'basic_plan');
$client->suspendAccount('exampleu', 'Non-payment');
$client->unsuspendAccount('exampleu');
$client->changePassword('exampleu', 'newpass456');
$client->changePackage('exampleu', 'premium_plan');
$client->destroyAccount('exampleu');
// Server info
$client->listAccounts();
$client->listPackages();
$client->getVersion();
$client->getAccountSummary('exampleu');
$client->showBandwidth('exampleu');
// SSO
$session = $client->createUserSession('exampleu', 'cpaneld');
$url = $session['data']['url']; // Redirect customer here
// Connection test
$result = $client->checkConnection();
// ['status' => 1, 'error' => false, 'verbose' => 'Connection successful.']
// UAPI (user-level operations)
$client->uapi('Email', 'list_pops', 'exampleu');
Raw API Calls
Any WHM API 1 function can be called directly via the magic method:
$client->modifyacct(['user' => 'exampleu', 'CONTACTEMAIL' => 'new@email.com']);
Available Shortcuts
Account Lifecycle
| Method | WHM API | Description |
|---|---|---|
createAccount($domain, $username, $password, $plan) |
createacct |
Create account |
destroyAccount($username) |
removeacct |
Delete account |
suspendAccount($username, $reason) |
suspendacct |
Suspend account |
unsuspendAccount($username) |
unsuspendacct |
Unsuspend account |
changePassword($username, $password) |
passwd |
Change password |
changePackage($username, $package) |
changepackage |
Change plan |
getAccountSummary($username) |
accountsummary |
Account details |
modifyAccount($username, $params) |
modifyacct |
Modify account attrs |
Server Management
| Method | WHM API | Description |
|---|---|---|
listAccounts() |
listaccts |
All accounts |
listPackages() |
listpkgs |
Available plans |
listSuspended() |
listsuspended |
Suspended accounts |
getVersion() |
version |
Server version |
showBandwidth($username) |
showbw |
Bandwidth stats |
SSO / Sessions
| Method | WHM API | Description |
|---|---|---|
createUserSession($username, $service) |
create_user_session |
Create login session |
Email (via UAPI)
| Method | UAPI Module | Description |
|---|---|---|
listEmailAccounts($username) |
Email::listpops |
List email accounts |
listForwards($username) |
Email::listforwards |
List forwarders |
addEmailAccount($username, $email, $password) |
Email::addpop |
Create email account |
changeEmailPassword($username, $email, $password) |
Email::passwdpop |
Change email password |
Error Handling
All API calls throw CpanelApiException on failure:
use LithiumHosting\CpanelApi\CpanelApiException;
try {
$client->createAccount('example.com', 'user', 'pass', 'plan');
} catch (CpanelApiException $e) {
// HTTP error, JSON parse error, or connection failure
Log::error('WHM API failed: ' . $e->getMessage());
}
Dependencies
guzzlehttp/guzzle: HTTP client
License
This package, laravel-cpanel-api is licensed under The MIT License (MIT). Please see License File for more information.
Is it any good?
Yes.
When people first hear about a new product, they frequently ask if it is any good. A Hacker News user remarked:
Note to self: Starting immediately, all raganwald projects will have a "Is it any good?" section in the readme, and the answer shall be "yes.".