ServerPilot API PHP Client
A PHP Client for ServerPilot API V1 using GuzzleHttp and PSR-4 autoloading support., (*1)
NOTICE This package is still under development
Installation
composer require noergaard/serverpilot
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., (*2)
use Noergaard\ServerPilot\Client;
$client = new Client('your_serverpilot_client_id', 'your_serverpilot_key');
Using Resources
This client package follows the same naming conventions for resources, provided by ServerPilot and their API documentation., (*3)
For further details about API endpoints, please visit the ServerPilot API V1 documentation., (*4)
Servers
To make requests to Server resources, make a call to the servers() method on the client object., (*5)
From all request to Server resources either and array of ServerEntity or a single ServerEntity will be returned., (*6)
A ServerEntity has public camelcase properties, matching the returned values from the ServerPilot API., (*7)
List All Servers
$servers = $client->servers()->all();
foreach($servers as $server)
{
var_dump($server->name);
}
Connect a New Server
There are multiple steps involved in connection a server to ServerPilot, (*8)
Please visit the ServerPilot API V1 documentation for further information., (*9)
| Parameter |
Type |
| Name |
string |
$server = $client->servers()->create('name');
// Api key to use for provision
$apiKey = $server->apiKey;
Retrieve/Get a Server
| Parameter |
Type |
| Server Id |
string |
$server = $client->servers()->get('serverId');
Update a Server
| Parameter |
Type |
| Server Id |
string |
| Firewall Enabled |
boolean |
| Auto Updates Enabled |
boolean |
$server = $client->servers()->update('serverId', true, false);
Delete a Server
| Parameter |
Type |
| Server Id |
string |
$server = $client->servers()->delete('serverId');
System Users
To make requests to System User resources, make a call to the systemUsers() method on the client object., (*10)
From all request to System User resources either and array of SystemUserEntity or a single SystemUserEntity will be returned., (*11)
A SystemUserEntity has public camelcase properties, matching the returned values from the ServerPilot API., (*12)
List All System Users
$systemUsers = $client->systemUsers()->all()
foreach($systemUsers as $systemUser)
{
var_dump($systemUser->name);
}
Create a System User
Notice User name length must be between 3 and 32 characters, lowercase ascii letters, digits or a dash., (*13)
Notice Password length must be at least 8 characters and no more than 200 characters long, with no leading or trailing whitespace., (*14)
Please visit the ServerPilot API V1 documentation for further information., (*15)
| Parameter |
Type |
| Server Id |
string |
| Username |
string |
| Password |
string |
$systemUser = $client->systemUsers()->create('serverId', 'username', 'password');
$id = $systemUser->id;
Retrieve/Get a System User
| Parameter |
Type |
| System User Id |
string |
$systemUser = $client->systemUsers()->get('systemUserId');
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., (*16)
Please visit the ServerPilot API V1 documentation for further information., (*17)
| Parameter |
Type |
| System User Id |
string |
| Password |
string |
$systemUser = $client->systemUsers()->update('systemUserId', 'password');
Delete a System User
| Parameter |
Type |
| System User Id |
string |
$systemUser = $client->systemUsers()->delete('systemUserId');
Apps
To make requests to App resources, make a call to the apps() method on the client object., (*18)
From all request to App resources either and array of AppEntity or a single AppEntity will be returned., (*19)
A AppEntity has public camelcase properties, matching the returned values from the ServerPilot API., (*20)
List All Apps
$apps = $client->apps()->all();
foreach($apps as $app
{
var_dump($app->name);
}
Create an App
Notice Upon creating a new app, the Server where the App will be created, is determined by the System User., (*21)
When creating an App you have the possibility to install WordPress at the same time., (*22)
If you wish to install WordPress, you have to provide the necessary information and credentials for the
WordPress install process., (*23)
To streamline this process, this package uses a WordPressFactory object, which instantiates the correct object to be passed to the ServerPilot API, (*24)
If you DO NOT want to install WordPress, you don't have to provide any data to that parameter., (*25)
| Parameter |
Type |
| App Name |
string |
| System User Id |
string |
| PHP Runtime |
string |
| Domains |
array |
| WordPress |
WordPress object or null |
To make the choice of PHP runtimes easier, the Apps class provides constants of the various runtimes supported by ServerPilot, (*26)
// 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, (*27)
$app = $client->apps()->create('appName', 'systemUserId', 'runtime', ['example.com', 'www.example.com']);
Create an App with WordPress, (*28)
| Wordpress Factory Parameters |
Type |
| Site Title |
string |
| Admin User Name |
string |
| Admin Password |
string |
| Admin Email |
string |
$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
| Parameters |
Type |
| App Id |
string |
$app = $client->apps()->get('appId');
Update an App
| Parameter |
Type |
| App Id |
string |
| PHP Runtime |
string |
| Domains |
array |
To make the choice of PHP runtimes easier, the Apps class provides constants of the various runtimes supported by ServerPilot, (*29)
// 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
| Parameters |
Type |
| App Id |
string |
$app = $client->apps()->delete('appId');
Custom SSL - AutoSSL - ForceSSL
These parts has not been implemented in this package yet,
but will be soon., (*30)
Databases
To make requests to Database resources, make a call to the databases() method on the client object., (*31)
From all request to Database resources either and array of DatabaseEntity or a single DatabaseEntity will be returned., (*32)
A DatabaseEntity has public camelcase properties, matching the returned values from the ServerPilot API., (*33)
List All Databases
$databases = $client->databases()->all();
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., (*34)
Notice Database User names must be at most 16 characters., (*35)
Notice Database passwords must be at least 8 and no more than 200 charachters long, with no leading or trailing whitespace., (*36)
Notice Database names must be between 3 and 32 characters, lowercase ascii letters, digits or a dash., (*37)
| Parameters |
Type |
| App Id |
string |
| Database Name |
string |
| Database User |
DatabaseUser object |
The DatabaseUserFactory object, takes the following parameters, (*38)
| Parameters |
Type |
| User Name |
string |
| Password |
string |
$databaseUser = DatabaseUserFactory::make('username', 'password');
$database = $client->databases()->create('appId', 'databaseName', $databaseUser);
Retrieve/Get an existing Database
| Parameters |
Type |
| Database Id |
string |
$database = $client->databases()->get('databaseId');
Update the Database User Password
| Parameters |
Type |
| Database Id |
string |
| Database User Id |
string |
| New Database Password |
string |
$database = $client->databases()->updatePassword('databaseId', 'databaseUserId', 'password');
Delete a Database
| Parameters |
Type |
| Database Id |
string |
$database = $client->databases()->delete('databaseId');
Actions
To make requests to Action resources, make a call to the actions() method on the client object., (*39)
From all request to Action resources either and array of ActionEntity or a single ActionEntity will be returned., (*40)
A ActionEntity has public camelcase properties, matching the returned values from the ServerPilot API., (*41)
Check the Status of an Action
You can check actions of any resource that are modifying data., (*42)
You are modifying data when you are creating, updating or deleting a resource, (*43)
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., (*44)
You can also just provide the action id if you like., (*45)
| Parameters |
Type |
| Action Id |
string or AbstractEntity |
Checking Action when Connecting a Server and passing the ServerEntity to the Status method, (*46)
$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, (*47)
$server = $client->servers()->create('name');
$action = $client->actions()->status($server->getActionId());
Todo
- [x] Implement Servers
- [x] Implement System Users
- [ ] Implement Apps
- [x] Implement Databases
- [x] Implement Actions
Todo on Apps
- [ ] Add a Custom SSL Certificate
- [ ] Enable AutoSSL
- [ ] Delete a Custom SSL Certificate or Disable AutoSSL
- [ ] Enable or Disable ForceSSL
Testing
There are two types of tests in this package: Unit tests and Integration tests., (*48)
Unit Tests
Are good to go out of the box., (*49)
To run these test you can run them by the Unit directory, (*50)
phpunit ./tests/Unit, (*51)
Integration Tests
Integration tests hits the endpoint on the ServerPilot API., (*52)
It is therefore required that your provide a ServerPilot client_id and key to run these test., (*53)
You can add these inside the TestCase class, which are placed under /tests/TestCase., (*54)
<?php
class TestCase extends PHPUnit_Framework_TestCase
{
protected $clientId;
protected $key;
public function setUp()
{
parent::setUp();
$this->clientId = 'your_client_id';
$this->key = 'your_key';
}
}