xililo / whm-api
A tidy PHP wrapper for the cPanel WHM API 1.
v1.0.0
2026-04-25 22:20 UTC
Requires
- php: ^8.1
- ext-curl: *
- ext-json: *
README
A tidy PHP wrapper for the cPanel WHM API 1.
Overview
This package provides a lightweight, dependency-minimal client for interacting with WHM API 1 JSON endpoints. It includes support for:
- WHM token authentication
- account management and account queries
- hosting plan creation, updates, and inspection
- login session and provider login URL helpers
Requirements
- PHP ^8.1
- ext-curl
- ext-json
Installation
composer require xililo/whm-api
Quick Start
<?php declare(strict_types=1); use Xililo\WhmApi\Config; use Xililo\WhmApi\Whm; $config = new Config( host: 'whm.example.com', username: 'root', token: 'your-api-token', ); $whm = new Whm($config); $accounts = $whm->accounts()->list(); foreach ($accounts->data('acct', []) as $account) { echo $account['user'] . PHP_EOL; }
Usage
Authentication
WHM token calls use the header format documented by cPanel:
Authorization: whm username:token
Create a WHM user session
$response = $whm->auth()->createUserSession( user: 'example', service: 'cpaneld', ); $url = $response->data('url');
Fetch a provider login URL
$response = $whm->auth()->getLoginUrl( provider: 'cPStore', urlAfterLogin: 'https://your-app.example.com/return', ); $url = $response->data('url');
Accounts
List accounts
$accounts = $whm->accounts()->list([ 'search' => 'example', 'searchtype' => 'domain', 'searchmethod' => 'exact', ]);
Create an account
$response = $whm->accounts()->create( username: 'example', domain: 'example.com', password: 'strong-password', plan: 'starter', );
Change package
$whm->accounts()->changePackage('example', 'business');
Suspend / unsuspend
$whm->accounts()->suspend('example', 'Non-payment'); $whm->accounts()->unsuspend('example');
Change password
$whm->accounts()->setPassword('example', 'new-password');
Hosting Plans
List plans
$plans = $whm->hostingPlans()->list();
Create a plan
$whm->hostingPlans()->create([ 'name' => 'starter', 'quota' => 10240, 'bwlimit' => 102400, 'maxftp' => 10, 'maxsql' => 10, ]);
Update a plan
$whm->hostingPlans()->update('starter', [ 'MAX_EMAIL_PER_HOUR' => 200, ]);
Inspect a plan
$plan = $whm->hostingPlans()->info('starter');
Response Model
Every resource returns an ApiResponse instance with helpers such as:
$response->successful(); $response->metadata(); $response->data(); $response->data('acct', []); $response->reason(); $response->command(); $response->raw(); $response->toArray();
Notes
- The client calls
https://{host}:2087/json-api/{function}by default. - It automatically appends
api.version=1. - The client is dependency-light and uses cURL directly.
- Extra parameters may be passed through for WHM-specific query options.
Links
- Packagist: https://packagist.org/packages/xililo/whm-api
- cPanel WHM API docs: https://api.docs.cpanel.net/whm/introduction
License
MIT