Skip to content

Creating a Server Manager

Server managers connect FOSSBilling to hosting control panels (cPanel, Plesk, DirectAdmin, etc.), enabling automatic account creation, suspension, and management.

Place your manager in:

src/library/Server/Manager/
└── YourManager.php

Extend Server_Manager and implement the required methods.

The Server_Manager base class defines these methods:

MethodPurpose
create()Create a hosting account
suspend()Suspend an account
unsuspend()Unsuspend an account
cancel()Cancel/delete an account
changePassword()Change account password
changePackage()Change hosting plan/package
<?php
class Server_Manager_YourManager extends Server_Manager
{
public function __construct($options)
{
parent::__construct($options);
if (!isset($this->config['api_key'])) {
throw new Server_Exception('API key is required');
}
}
public static function getForm(): array
{
return [
'label' => 'YourManager',
'form' => [
'api_key' => ['text', ['label' => 'API Key']],
'api_secret' => ['password', ['label' => 'API Secret']],
],
];
}
public function create(Server_Account $account): bool
{
$params = [
'username' => $account->getUsername(),
'password' => $account->getPassword(),
'domain' => $account->getDomain(),
'package' => $account->getPackage()->getName(),
'email' => $account->getEmail(),
];
$response = $this->apiRequest('create_account', $params);
if ($response['success']) {
$account->setUsername($response['username']);
return true;
}
throw new Server_Exception($response['error'] ?? 'Failed to create account');
}
public function suspend(Server_Account $account): bool
{
return $this->apiRequest('suspend_account', [
'username' => $account->getUsername(),
]);
}
public function unsuspend(Server_Account $account): bool
{
return $this->apiRequest('unsuspend_account', [
'username' => $account->getUsername(),
]);
}
public function cancel(Server_Account $account): bool
{
return $this->apiRequest('delete_account', [
'username' => $account->getUsername(),
]);
}
public function changePassword(Server_Account $account, string $newPassword): bool
{
return $this->apiRequest('update_password', [
'username' => $account->getUsername(),
'password' => $newPassword,
]);
}
public function changePackage(Server_Account $account, Server_Package $package): bool
{
return $this->apiRequest('change_package', [
'username' => $account->getUsername(),
'package' => $package->getName(),
]);
}
private function apiRequest(string $action, array $params = []): array
{
$url = $this->config['api_url'] . '/' . $action;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($params));
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Bearer ' . $this->config['api_key'],
'Content-Type: application/json',
]);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($httpCode !== 200) {
throw new Server_Exception('API request failed: ' . $response);
}
return json_decode($response, true) ?? [];
}
}
  1. Add your server in System → Hosting plans and servers
  2. Create a hosting plan linked to your server
  3. Create a hosting product using that plan
  4. Place a test order
  5. Verify account creation in the control panel
  6. Test suspend, unsuspend, and cancellation
  • Server_Manager — Base class with inline docs
  • Existing managers in src/library/Server/Manager/

Join our Discord for assistance with your server manager.