https://github.com/hetzner-cloud-php/client
☁️ Plug 'n play PHP client for Hetzner's Cloud API.
https://github.com/hetzner-cloud-php/client
api client hetzner-cloud php sdk
Last synced: 5 months ago
JSON representation
☁️ Plug 'n play PHP client for Hetzner's Cloud API.
- Host: GitHub
- URL: https://github.com/hetzner-cloud-php/client
- Owner: hetzner-cloud-php
- License: mit
- Created: 2025-01-10T06:39:31.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-05-12T22:03:18.000Z (about 1 year ago)
- Last Synced: 2025-06-12T05:16:58.811Z (about 1 year ago)
- Topics: api, client, hetzner-cloud, php, sdk
- Language: PHP
- Homepage: https://hetznercloudphp.netlify.app/
- Size: 2.68 MB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
## Hetzner Cloud PHP
A PHP client for the Hetzner Cloud API. The goal of this project is to provide an easy-to-use and framework agnostic PHP
PHP client for projects and applications interacting with Hetzner Cloud. Some use cases might include:
- Getting metrics for all servers within a project
- Programmatically creating firewalls
- Searching for available datacenters
## Table of Contents
- [Getting started](#getting-started)
- [Usage](#usage)
- [Database](#database)
- [Firewalls](#firewalls)
- [Servers](#servers)
## Getting started
The client is available as a composer packager that can be installed in any project using composer:
```bash
composer require hetzner-cloud-php/client
```
Since the client is compatible with any PSR-18 HTTP client, any commonly used HTTP client can be used thanks
to our dependency on `php-http/discovery`. Once both dependencies have been installed, you may start interaction
with [Hetzner Cloud API](https://docs.hetzner.cloud/):
```php
/** @var string $apiKey */
$apiKey = $_ENV['HETZNER_CLOUD_API_KEY'];
$client = HetznerCloud::client($apiKey);
// Create a server
$response = $createdServer = $client->servers()->createServer([
'name' => 'test-server',
'server_type' => 'cpx11',
'image' => 'ubuntu-24.04',
]);
echo $response->server->name; // 'test-server'
```
For a comprehensive set of examples, take a look at the [examples](/examples) directory.
## Usage
### Datacenters
#### Get all datacenters
Gets a list of available datacenters.
```php
$response = $client->datacenters()->getDatacenters(sort: 'name:desc');
echo $response->datacenters // array
echo $response->meta // Meta::class
echo $response->toArray() // ['datacenter' => ['id' => 42, ...], 'meta' => [...]]
```
#### Get a datacenter
Gets a single datacenter.
```php
$response = $client->datacenters()->getDatacenter(42);
echo $response->datacenter // Datacenter::class
echo $response->toArray() // ['datacenter' => ['id' => 42, ...], 'error' => null]
```
### `Firewalls`
#### Get a firewall
Retrieves a single firewall for a project.
```php
$response = $client->firewalls()->getFirewall(1337);
$response->firewall; // Firewall::class
$response->toArray(); // ['firewall' => ['id => 1337', ...]]
```
#### Get firewalls
Retrieves all firewalls for a project, with a few optional query parameters.
```php
$response = $client->firewalls()->getFirewalls(name: 'coolify', labelSelector: 'foo');
$response->firewalls; // array
foreach ($response->firewalls as $firewall) {
$firewall->id;
$firewall->name;
// ...
}
$response->toArray(); // ['firewalls' => [...], 'meta' => [...]]
```