cPanel API Wrapper for Laravel
Find a file
Troy Siedsma fc8d6179ad README: drop the LiBilling commercial preamble from the License section
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>
2026-05-22 15:40:43 +00:00
config Re-platform onto LithiumHosting/laravel-cpanel-api Forgejo origin 2026-05-22 13:14:19 +00:00
src Re-platform onto LithiumHosting/laravel-cpanel-api Forgejo origin 2026-05-22 13:14:19 +00:00
.gitignore Re-platform onto LithiumHosting/laravel-cpanel-api Forgejo origin 2026-05-22 13:14:19 +00:00
CHANGELOG.md Re-platform onto LithiumHosting/laravel-cpanel-api Forgejo origin 2026-05-22 13:14:19 +00:00
composer.json Re-platform onto LithiumHosting/laravel-cpanel-api Forgejo origin 2026-05-22 13:14:19 +00:00
CONTRIBUTING.md Re-platform onto LithiumHosting/laravel-cpanel-api Forgejo origin 2026-05-22 13:14:19 +00:00
LICENSE.md LICENSE: Copyright (c) Lithium Holdings, LLC 2026-05-22 15:13:42 +00:00
README.md README: drop the LiBilling commercial preamble from the License section 2026-05-22 15:40:43 +00:00

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: CpanelApiException for 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.".