Skip to content

Creating WHM packages from the API — package as code, not as form submissions

WHM packages created through the UI accumulate inconsistencies. Creating them through the API with a versioned source file is the only way to keep packages identical across a fleet.

A new package gets created in WHM through the Edit Package form. Three months later, the same package needs to exist on a second server, and the operator recreates it by memory — close, but not exactly the same. The two packages diverge over time as edits happen on each side. The fix is to treat packages as source code: a YAML or JSON file that describes the package, applied through whmapi1 addpkg (or editpkg for updates) to every server in the fleet.

What’s happening

whmapi1 addpkg accepts every field the WHM UI exposes — quota, bandwidth, feature list, max addons, max databases, theme, locale, CPU/memory/IO limits if CloudLinux is present. The call is deterministic: given the same inputs, you get the same package. The UI obscures this because it pre-fills fields with the logged-in reseller’s defaults, so two operators clicking through the form produce different packages from the same intent.

How to verify

List packages currently on the server and inspect one in detail:

whmapi1 list_packages
whmapi1 listpkgext pkg=gold-2026
ls /var/cpanel/packages/
cat /var/cpanel/packages/gold-2026
diff /var/cpanel/packages/gold-2026 /tmp/master/gold-2026

The on-disk package file is the canonical state. The listpkgext output is what cPanel will tell consumers. They should match; any divergence is local drift.

The fix

  1. Define the package as a source file — a YAML or JSON that lists every field and value. Keep it in your config-management repo, one file per package.
  2. Apply through whmapi1 addpkg in your provisioning script:
whmapi1 addpkg \
  name=gold-2026 \
  quota=51200 \
  bwlimit=1048576000 \
  maxsubdomains=50 \
  maxpop=unlimited \
  featurelist=corporate \
  cpmod=jupiter \
  language=en \
  cgi=1 \
  shell=jailshell
  1. For updates, use editpkg instead of addpkg. The shape is identical except for the verb; cPanel updates the existing package in place.
  2. Run the same script against every server in the fleet. Drift detection becomes a diff between expected (the source file) and actual (listpkgext output).
  3. Mark packages as “managed by automation” — add a note field: featurelist=corporate cpmod=jupiter notes="managed by config repo, hand edits will be overwritten". The notes field is read-only operationally but visible to operators in WHM.
  4. For package retirements, the same flow runs whmapi1 deletepkg name=silver-2022. Source-of-truth retirements deletion is in the source file; reapply across the fleet to converge.

Package-as-code is part of how Stack Harbor’s cPanel and WHM management practice keeps multi-server fleets converged on the same package definitions without manual reconciliation.