hetzner-cloud-php / client
A PHP client for the Hetzner Cloud API.
Requires
- php: ^8.4
- hetzner-cloud-php/http-client-utilities: ^0.1
- nesbot/carbon: ^3.8
- php-http/discovery: ^1.20
- php-http/multipart-stream-builder: ^1.4
- psr/http-client: ^1.0
- psr/http-client-implementation: ^1.0
- psr/http-factory-implementation: ^1.0
- psr/http-message: ^2.0
Requires (Dev)
- guzzlehttp/guzzle: ^7.9
- laravel/pint: ^1.19
- mockery/mockery: ^1.6
- peckphp/peck: ^0.1.1
- pestphp/pest: ^3.7
- pestphp/pest-plugin-faker: ^3.0
- pestphp/pest-plugin-watch: 3.x-dev
- phpstan/extension-installer: ^1.4
- phpstan/phpstan: ^2.1
- phpstan/phpstan-deprecation-rules: ^2.0
- phpstan/phpstan-phpunit: ^2.0
- phpstan/phpstan-strict-rules: ^2.0
- rector/rector: ^2.0
- vlucas/phpdotenv: ^5.6
This package is auto-updated.
Last update: 2025-05-12 22:03:20 UTC
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
The client is available as a composer packager that can be installed in any project using composer:
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:
/** @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 directory.
Usage
Datacenters
Get all datacenters
Gets a list of available datacenters.
$response = $client->datacenters()->getDatacenters(sort: 'name:desc'); echo $response->datacenters // array<int, Datacenter> echo $response->meta // Meta::class echo $response->toArray() // ['datacenter' => ['id' => 42, ...], 'meta' => [...]]
Get a datacenter
Gets a single datacenter.
$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.
$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.
$response = $client->firewalls()->getFirewalls(name: 'coolify', labelSelector: 'foo'); $response->firewalls; // array<int, Firewall::class> foreach ($response->firewalls as $firewall) { $firewall->id; $firewall->name; // ... } $response->toArray(); // ['firewalls' => [...], 'meta' => [...]]