Introduction to SolusVM API
The SolusVM API allows you to programmatically control your VPS without logging into the provider's management panel. This facilitates automation, mobile device management, and integration with other systems. This guide focuses on using the API to reboot, start, and check the status of your VPS.
Prerequisites: Obtain API Credentials
To use the SolusVM API, you first need to obtain authentication details from your control panel.
- Log in to your VPS provider's SolusVM management panel.
- Find and click the "API" tab in the control panel.
- Record the values for
API KeyandAPI Hash.
Important: Keep these credentials secure and never share them. They act as the "keys" to your VPS. You can click the "Generate" button to regenerate new Key and Hash values at any time.
Create an API Management Script
You can call the SolusVM API using a simple PHP script. Below is a functional example that includes status checking, boot, and reboot functions, with basic safety confirmation.
Script Code and Deployment
Create a new PHP file (e.g., vps_manager.php) and copy the following code into it.
<?php
// Error reporting for debugging
ini_set('display_errors', 1);
error_reporting(E_ALL ^ E_NOTICE);
// --- IMPORTANT: Replace with your actual details ---
$api_key = "YOUR_API_KEY_HERE";
$api_hash = "YOUR_API_HASH_HERE";
$solusvm_url = "https://your-solusvm-master.com";
// ------------------------------------------
if (!empty($_GET['action'])) {
$action = $_GET['action'];
$confirmed = $_GET['confirmed'] ?? false;
$allowed_actions = ['status', 'boot', 'reboot', 'shutdown'];
if (!in_array($action, $allowed_actions)) {
echo "<p>Error: Unsupported action!</p>";
} elseif (in_array($action, ['boot', 'reboot', 'shutdown']) && !$confirmed) {
$action_map = ['boot' => 'Start', 'reboot' => 'Reboot', 'shutdown' => 'Shutdown'];
echo '<p>Are you sure you want to ' . $action_map[$action] . ' the VPS? ';
echo '<a href="?action=' . $action . '&confirmed=1">Confirm</a> | ';
echo '<a href="./">Cancel</a></p>';
} else {
$api_endpoint = $solusvm_url . "/api/client/command.php";
$request_url = $api_endpoint . "?key=" . urlencode($api_key) . "&hash=" . urlencode($api_hash) . "&action=" . $action;
$response = @file_get_contents($request_url);
if ($response === FALSE) {
echo "<p>Error: Could not connect to SolusVM API server. Check network and address.</p>";
} else {
$xml = simplexml_load_string($response);
if ($xml) {
$status = (string)$xml->status;
$statusmsg = (string)$xml->statusmsg;
if ($status == "error") {
echo "<p>API returned error: " . htmlspecialchars($statusmsg) . "</p>";
} elseif ($status == "success") {
$messages = [
'online' => 'VPS is running!',
'offline' => 'VPS is shut down.',
'rebooted' => 'VPS rebooted successfully!',
'shutdown' => 'VPS has been shut down.',
'booted' => 'VPS started successfully!'
];
if (isset($messages[$statusmsg])) {
echo "<p>" . $messages[$statusmsg] . "</p>";
} else {
echo "<p>Action successful. Message: " . htmlspecialchars($statusmsg) . "</p>";
}
}
} else {
echo "<p>Error: Could not parse API response.</p>";
}
}
echo '<hr />';
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>VPS Remote Management</title>
<style>
body { font-family: sans-serif; margin: 2em; }
ul { list-style: none; padding: 0; }
li { margin: 1em 0; }
a { text-decoration: none; padding: 0.5em 1em; background: #0073aa; color: white; border-radius: 4px; }
a:hover { background: #005a87; }
.warning { color: #d63638; font-weight: bold; }
</style>
</head>
<body>
<h1>VPS Remote Management Panel</h1>
<p class="warning">Warning: The following actions will directly affect your server.</p>
<ul>
<li><a href="?action=status">? Check VPS Status</a></li>
<li><a href="?action=boot">? Boot VPS</a></li>
<li><a href="?action=reboot">? Reboot VPS</a></li>
<li><a href="?action=shutdown">⏹️ Shutdown VPS</a></li>
</ul>
<p><small>Tip: Replace the API Key, Hash, and SolusVM URL in the script with your own information.</small></p>
</body>
</html>
Deployment and Usage Steps
- Edit Configuration: Open the script in a text editor. Find the
$api_key,$api_hash, and$solusvm_urlvariables at the top and replace their values with your actual credentials. - Upload File: Upload the PHP file to a web-accessible directory (e.g.,
public_htmlorwwwroot) on any PHP-enabled web server. - Access Panel: Access the file's URL via a browser (e.g.,
https://yourdomain.com/vps_manager.php). - Perform Actions: Click the links on the page to check status or perform actions like boot or reboot. Critical actions require a confirmation.
Security Recommendations and Notes
- Access Control: Place the script in a protected directory or use
.htaccessfor basic authentication to prevent unauthorized access. - HTTPS: Ensure your SolusVM master URL supports HTTPS and use
https://in the script to secure API key transmission. - Error Handling: The example includes basic error handling. For production, consider more robust logging and error messages.
- API Limits: Be aware that your SolusVM provider may impose rate limits on API calls; avoid excessive requests.
- Script Updates: This script is a general example. Different SolusVM versions or custom provider implementations may have slight variations in API response format; adjust parsing logic as needed.
Following these steps, you can conveniently manage your VPS remotely via a simple web interface without logging into the complex backend panel each time.