WHMCS + DirectAdmin: Automate Account Setup, Billing and Suspensions

Connect WHMCS to DirectAdmin with a login key, map products to packages, set the cron and automation rules, then test the whole billing cycle safely.

Published
Reading time
6 min

A hosting business with ten clients can be run by hand. At thirty, creating accounts and chasing invoices is a part-time job you are not paid for. WHMCS and DirectAdmin together remove that job: a paid order creates the account, an unpaid invoice suspends it, and a late payment brings it back, all without you logging in to either panel. This guide sets up that loop and tests every stage before a real client depends on it.

What talks to what

WHMCS ships with a DirectAdmin server module. It calls the DirectAdmin API over HTTPS on port 2222 using a DirectAdmin login, and it creates each client as a user under that login. So you need three things in place first:

  • A DirectAdmin reseller login (or admin on your own server). On a reseller plan this is the login you were given.
  • At least one user package created in DirectAdmin. WHMCS never creates packages, it only names one. See creating packages and user accounts.
  • Port 2222 reachable from the server WHMCS runs on.

Create a login key in DirectAdmin

Do not put your reseller password into WHMCS. A login key is a second credential for the same account that you can restrict and revoke.

  1. Log in to DirectAdmin as the reseller and open Login Keys. In the Evolution skin it sits under Advanced Features; the menu search finds it in any layout.
  2. Choose to create a new key. Give it a name such as whmcs.
  3. Let DirectAdmin generate the key value, or paste a long random string of your own. Copy it now, it is not shown again.
  4. Set the expiry to never, and leave the number of uses unlimited.
  5. Under allowed IPs, enter the public IP of the WHMCS server and nothing else.
  6. Allow all commands to begin with. Once orders are flowing, narrow the list to the calls the module makes, such as CMD_API_ACCOUNT_USER, CMD_API_SELECT_USERS and CMD_API_PACKAGES_USER.
  7. Confirm with your current DirectAdmin password and save.

Test the key from the WHMCS server before you touch WHMCS itself:

bash
curl -s -u 'resellername:PASTE_LOGIN_KEY' \
  'https://server1.example.com:2222/CMD_API_PACKAGES_USER'

A working key returns your package names as a URL-encoded list such as list[]=Starter&list[]=Business. A login page, an error or a timeout means the key, the IP restriction, the username or the firewall is wrong.

Tip: the outbound IP of the WHMCS server is not always the IP its site resolves to. Run curl -s https://ifconfig.me there to see the address DirectAdmin will see.

Add the server in WHMCS

Go to Configuration → System Settings → Servers and add a new server.

Field Value
Name anything you recognise, e.g. da-fr-01
Hostname the panel hostname, e.g. server1.example.com
IP address the server's shared IP
Module DirectAdmin
Username your reseller username
Password the login key, not your password
Secure ticked, so WHMCS uses SSL
Port 2222

Use Test Connection before saving. Fill in the nameserver fields on the same page, because the welcome email takes them from here, then create a server group containing this server. Products attach to groups, not servers.

Map each product to a package

Under Configuration → System Settings → Products/Services, open a hosting product and go to the Module Settings tab.

  • Module: DirectAdmin, and the server group you just made.
  • Package name: exactly as DirectAdmin shows it, including case. Starter and starter are different packages to the API.
  • Leave the dedicated IP option off for ordinary shared accounts.
  • Choose Automatically setup the product as soon as the first payment is received.

On the Details tab, tick Require Domain, because DirectAdmin cannot create a user without one, and pick the welcome email. Building the products is covered in WHMCS products, pricing and configurable options.

Tip: name packages for what they are (wp-5gb, biz-20gb), not for what you charge. Renaming a package in DirectAdmin later breaks the mapping silently until the next order fails.

The welcome email

The stock hosting welcome template merges the username, password, hostname and nameservers of the service. Edit it under Email Templates and make sure it contains the panel address with the port:

Control panel: https://{$service_server_hostname}:2222
Username: {$service_username}
Password: {$service_password}
Nameservers: {$service_ns1} and {$service_ns2}

If the email never arrives, see WHMCS not sending emails.

The cron: what actually does the automating

None of the billing automation happens unless the WHMCS cron runs. On DirectAdmin, add it at user level under Cron Jobs, using the full path to the same PHP version your WHMCS site runs on:

*/5 * * * * /usr/local/php83/bin/php -q /home/USERNAME/domains/yourbrand.com/public_html/billing/crons/cron.php

CustomBuild installs each PHP version under /usr/local/phpXX/bin/php; adjust the number and the path. Every five minutes is correct: the daily tasks still run once a day, and the other runs work through the queue.

What the cron does:

Task Effect in DirectAdmin
Generate invoices, send reminders none, emails only
Suspend overdue services the user is suspended, data is kept
Unsuspend on payment the user is unsuspended
Terminate the user and all of its data are deleted
Create on payment new paid orders are provisioned

Automation settings worth changing

Open Configuration → System Settings → Automation Settings. A sensible starting point for a small host:

  • Invoice generation: 14 days before the due date.
  • Enable Suspension: on, at 5 to 7 days overdue.
  • Enable Unsuspension: on.
  • Enable Termination: off until you trust the setup, then 30 days or more overdue.

Tip: leave termination off for the first few months and delete accounts by hand. A suspended account costs a little disk. A wrongly terminated one costs a client.

The same page shows when the cron last ran. If that time is stale, WHMCS cron not running goes through the causes.

Test the full cycle with a dummy order

Do this once per product before selling it.

  1. Create a test client and place an order with a made-up domain.
  2. Mark the invoice paid. Within a few minutes the user should appear in DirectAdmin under Reseller Level → List Users, on the right package.
  3. Read the welcome email and log in with the details in it.
  4. On the service page in WHMCS, run the Suspend module command, check the site shows as suspended, then Unsuspend.
  5. Run Terminate and confirm the user is gone from DirectAdmin.

Module commands run by hand show the DirectAdmin response on screen, which is quicker than waiting for the cron.

Common failures

The package does not exist, or the account is created with the wrong limits. The name in Module Settings does not match a user package owned by this reseller. Compare it with the output of the curl test above.

Test Connection fails although the key is right. The login key's allowed IP list does not include the address WHMCS connects from. It also appears months later, when WHMCS moves to another server and the key is still pinned to the old IP.

Orders are paid but nothing is created. The cron is not running, or it runs under a PHP version without ionCube. Failed actions are listed under Utilities → Module Queue, where they can be retried once the cause is fixed.

No detail on why a call failed. Turn on module debug logging in the Module Log, repeat the action, read the raw response, then turn logging off.

What the automation does not cover

WHMCS suspends for non-payment. Disk usage, spam complaints and hacked sites are still yours to watch.

On our reseller plans a WHMCS licence is included with annual Partner Pro and available as an add-on on the other tiers. We supply the licence but not WHMCS installation or setup support, which is why the steps above are written to be done on your own.

#whmcs#directadmin#automation#provisioning#billing#reseller

Keep reading

More from WHMCS

All guides

WHMCS

How to Connect WHMCS to Plesk for Automatic Provisioning

Add your Plesk server to WHMCS, map products to service plans, and fix the errors that stop accounts being created, including the 1019 password policy error.

4 min read →

WHMCS

WHMCS Cron Not Running: How to Find the Cause and Fix It

Why invoices and suspensions stop when the WHMCS cron fails, the exact cron command for WHMCS 9, how to read the cron log, and the six failures we see most.

4 min read →

WHMCS

How to Install WHMCS on a Plesk Server, Step by Step

WHMCS 9 requirements (PHP 8.2+, ionCube 13, MySQL), creating the site in Plesk, running the installer, the cron job and the first settings to lock down.

4 min read →