PHPackages                             noergaard/serverpilot - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. noergaard/serverpilot

ActiveLibrary[API Development](/categories/api)

noergaard/serverpilot
=====================

PHP API Client for ServerPilot's RESTful API

v0.1.0(9y ago)0221MITPHPPHP &gt;=5.5.9

Since Aug 25Pushed 9y ago1 watchersCompare

[ Source](https://github.com/ThomasNoergaard/serverpilot-php-client)[ Packagist](https://packagist.org/packages/noergaard/serverpilot)[ RSS](/packages/noergaard-serverpilot/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependencies (4)Versions (2)Used By (0)

ServerPilot API PHP Client
==========================

[](#serverpilot-api-php-client)

A PHP Client for ServerPilot API V1 using GuzzleHttp and PSR-4 autoloading support.

### NOTICE This package is still under development

[](#notice-this-package-is-still-under-development)

Installation
------------

[](#installation)

```
composer require noergaard/serverpilot

```

Getting Started
---------------

[](#getting-started)

To get started, simply new up the Client and provide your `client_id` and `key` from ServerPilot and you're ready to go.

```
use Noergaard\ServerPilot\Client;

$client = new Client('your_serverpilot_client_id', 'your_serverpilot_key');
```

Using Resources
---------------

[](#using-resources)

This client package follows the same naming conventions for resources, provided by ServerPilot and their API documentation.

For further details about API endpoints, please visit the [ServerPilot API V1](https://github.com/ServerPilot/API) documentation.

### Servers

[](#servers)

To make requests to Server resources, make a call to the `servers()` method on the `client` object.

From all request to Server resources either and array of `ServerEntity` or a single `ServerEntity` will be returned.

A `ServerEntity` has public camelcase properties, matching the returned values from the ServerPilot API.

#### List All Servers

[](#list-all-servers)

```
$servers = $client->servers()->all();

foreach($servers as $server)
{
    var_dump($server->name);
}
```

#### Connect a New Server

[](#connect-a-new-server)

There are multiple steps involved in connection a server to ServerPilot

Please visit the [ServerPilot API V1](https://github.com/ServerPilot/API) documentation for further information.

ParameterTypeNamestring```
$server = $client->servers()->create('name');

// Api key to use for provision
$apiKey = $server->apiKey;
```

#### Retrieve/Get a Server

[](#retrieveget-a-server)

ParameterTypeServer Idstring```
$server = $client->servers()->get('serverId');
```

#### Update a Server

[](#update-a-server)

ParameterTypeServer IdstringFirewall EnabledbooleanAuto Updates Enabledboolean```
$server = $client->servers()->update('serverId', true, false);
```

#### Delete a Server

[](#delete-a-server)

ParameterTypeServer Idstring```
$server = $client->servers()->delete('serverId');
```

### System Users

[](#system-users)

To make requests to System User resources, make a call to the `systemUsers()` method on the `client` object.

From all request to System User resources either and array of `SystemUserEntity` or a single `SystemUserEntity` will be returned.

A `SystemUserEntity` has public camelcase properties, matching the returned values from the ServerPilot API.

#### List All System Users

[](#list-all-system-users)

```
$systemUsers = $client->systemUsers()->all()

foreach($systemUsers as $systemUser)
{
    var_dump($systemUser->name);
}
```

#### Create a System User

[](#create-a-system-user)

**Notice** User name length **must** be between 3 and 32 characters, lowercase ascii letters, digits or a dash.

**Notice** Password length **must** be **at least** 8 characters and **no more** than 200 characters long, with no leading or trailing whitespace.

Please visit the [ServerPilot API V1](https://github.com/ServerPilot/API) documentation for further information.

ParameterTypeServer IdstringUsernamestringPasswordstring```
$systemUser = $client->systemUsers()->create('serverId', 'username', 'password');

$id = $systemUser->id;
```

#### Retrieve/Get a System User

[](#retrieveget-a-system-user)

ParameterTypeSystem User Idstring```
$systemUser = $client->systemUsers()->get('systemUserId');
```

#### Update a System User

[](#update-a-system-user)

**Notice** Password length **must** be **at least** 8 characters and **no more** than 200 characters long, with no leading or trailing whitespace.

Please visit the [ServerPilot API V1](https://github.com/ServerPilot/API) documentation for further information.

ParameterTypeSystem User IdstringPasswordstring```
$systemUser = $client->systemUsers()->update('systemUserId', 'password');
```

#### Delete a System User

[](#delete-a-system-user)

ParameterTypeSystem User Idstring```
$systemUser = $client->systemUsers()->delete('systemUserId');
```

### Apps

[](#apps)

To make requests to App resources, make a call to the `apps()` method on the `client` object.

From all request to App resources either and array of `AppEntity` or a single `AppEntity` will be returned.

A `AppEntity` has public camelcase properties, matching the returned values from the ServerPilot API.

#### List All Apps

[](#list-all-apps)

```
$apps = $client->apps()->all();

foreach($apps as $app
{
    var_dump($app->name);
}
```

#### Create an App

[](#create-an-app)

**Notice** Upon creating a new app, the Server where the App will be created, is determined by the System User.

When creating an App you have the possibility to install WordPress at the same time.

If you wish to install WordPress, you have to provide the necessary information and credentials for the WordPress install process.

To streamline this process, this package uses a `WordPressFactory` object, which instantiates the correct object to be passed to the ServerPilot API

If you **DO NOT** want to install WordPress, you don't have to provide any data to that parameter.

ParameterTypeApp NamestringSystem User IdstringPHP RuntimestringDomainsarrayWordPressWordPress object *or* nullTo make the choice of PHP runtimes easier, the `Apps` class provides constants of the various runtimes supported by ServerPilot

```
// Use PHP 5.4
$runtime = Apps::PHP54;

// Use PHP 5.5
$runtime = Apps::PHP55;

// Use PHP 5.6
$runtime = Apps::PHP56;

// Use PHP 7.0
$runtime = Apps::PHP70;

// Use PHP 7.1
$runtime = Apps::PHP71;
```

**Create an App without WordPress**

```
$app = $client->apps()->create('appName', 'systemUserId', 'runtime', ['example.com', 'www.example.com']);
```

**Create an App with WordPress**

Wordpress Factory ParametersTypeSite TitlestringAdmin User NamestringAdmin PasswordstringAdmin Emailstring```
$wordpress = WordPressFactory::make('Site Title', 'admin','password', 'john@example.com');

$app = $client->apps()->create('appName', 'systemUserId', 'runtime', ['example.com', 'www.example.com'], $wordpress);
```

#### Retrieve/Get Details of an App

[](#retrieveget-details-of-an-app)

ParametersTypeApp Idstring```
$app = $client->apps()->get('appId');
```

#### Update an App

[](#update-an-app)

ParameterTypeApp IdstringPHP RuntimestringDomainsarrayTo make the choice of PHP runtimes easier, the `Apps` class provides constants of the various runtimes supported by ServerPilot

```
// Use PHP 5.4
$runtime = Apps::PHP54;

// Use PHP 5.5
$runtime = Apps::PHP55;

// Use PHP 5.6
$runtime = Apps::PHP56;

// Use PHP 7.0
$runtime = Apps::PHP70;

// Use PHP 7.1
$runtime = Apps::PHP71;
```

```
$app = $client->apps()->update('appId', 'runtime', ['example.com', 'www.example.com']);
```

#### Delete an App

[](#delete-an-app)

ParametersTypeApp Idstring```
$app = $client->apps()->delete('appId');
```

#### Custom SSL - AutoSSL - ForceSSL

[](#custom-ssl---autossl---forcessl)

These parts has not been implemented in this package yet, but will be soon.

### Databases

[](#databases)

To make requests to Database resources, make a call to the `databases()` method on the `client` object.

From all request to Database resources either and array of `DatabaseEntity` or a single `DatabaseEntity` will be returned.

A `DatabaseEntity` has public camelcase properties, matching the returned values from the ServerPilot API.

#### List All Databases

[](#list-all-databases)

```
$databases = $client->databases()->all();
```

#### Create a Database

[](#create-a-database)

To create a Database in an App, a Database user object is required by the ServerPilot API. This package streamlines this process by using a `DatabaseUserFactory` object.

**Notice** Database User names **must** be **at most** 16 characters.

**Notice** Database passwords **must** be **at least** 8 and **no more** than 200 charachters long, with no leading or trailing whitespace.

**Notice** Database names **must** be between 3 and 32 characters, lowercase ascii letters, digits or a dash.

ParametersTypeApp IdstringDatabase NamestringDatabase UserDatabaseUser objectThe `DatabaseUserFactory` object, takes the following parameters

ParametersTypeUser NamestringPasswordstring```
$databaseUser = DatabaseUserFactory::make('username', 'password');

$database = $client->databases()->create('appId', 'databaseName', $databaseUser);
```

#### Retrieve/Get an existing Database

[](#retrieveget-an-existing-database)

ParametersTypeDatabase Idstring```
$database = $client->databases()->get('databaseId');
```

#### Update the Database User Password

[](#update-the-database-user-password)

ParametersTypeDatabase IdstringDatabase User IdstringNew Database Passwordstring```
$database = $client->databases()->updatePassword('databaseId', 'databaseUserId', 'password');
```

#### Delete a Database

[](#delete-a-database)

ParametersTypeDatabase Idstring```
$database = $client->databases()->delete('databaseId');
```

### Actions

[](#actions)

To make requests to Action resources, make a call to the `actions()` method on the `client` object.

From all request to Action resources either and array of `ActionEntity` or a single `ActionEntity` will be returned.

A `ActionEntity` has public camelcase properties, matching the returned values from the ServerPilot API.

#### Check the Status of an Action

[](#check-the-status-of-an-action)

You can check actions of any resource that are modifying data.

You are modifying data when you are `creating`, `updating` or `deleting` a resource

To check an action for a resource, you can just pass the resource entity as a parameter to the `status()` method on the `action` object.

You can also just provide the `action id` if you like.

ParametersTypeAction Idstring *or* AbstractEntity**Checking Action when Connecting a Server and passing the ServerEntity to the Status method**

```
$server = $client->servers()->create('name');

$action = $client->actions()->status($server);
```

**Checking Action when Connecting a Server and passing the Action Id to the Status method**

```
$server = $client->servers()->create('name');

$action = $client->actions()->status($server->getActionId());
```

Todo
----

[](#todo)

- Implement Servers
- Implement System Users
- Implement Apps
- Implement Databases
- Implement Actions

#### Todo on Apps

[](#todo-on-apps)

- Add a Custom SSL Certificate
- Enable AutoSSL
- Delete a Custom SSL Certificate or Disable AutoSSL
- Enable or Disable ForceSSL

Testing
-------

[](#testing)

There are two types of tests in this package: Unit tests and Integration tests.

#### Unit Tests

[](#unit-tests)

Are good to go out of the box.

To run these test you can run them by the `Unit` directory

`phpunit ./tests/Unit`

#### Integration Tests

[](#integration-tests)

Integration tests hits the endpoint on the ServerPilot API.

It is therefore required that your provide a ServerPilot `client_id` and `key` to run these test.

You can add these inside the `TestCase` class, which are placed under `/tests/TestCase`.

```
