dev-master
9999999-devSDK for PHP for accessing the official Laravel Forge API
MIT
The Requires
by Denis Lam
SDK for PHP for accessing the official Laravel Forge API
#, (*1)
The Laravel Forge API SDK for PHP makes it easy for developers to access Laravel Forge in their PHP code via Forge's official REST API, and build robust applications and software to automatically provision, manage, and deploy unlimited PHP applications on AWS, DigitalOcean, Linode, etc. You can get started in minutes by installing the SDK through Composer or by downloading a single zip or phar file from our latest release., (*2)
The Laravel Forge API SDK for PHP can be installed via Composer by requiring the
guzzlehttp/guzzle
package (see: GuzzleHTTP) and registering a PSR-4 autoloader
for the Laravel_Forge_API_PHP_SDK
namespace in your project's composer.json
., (*3)
{ "require": { "guzzlehttp/guzzle": "~6.0" }, "autoload": { "psr-4": { "Laravel_Forge_API_PHP_SDK\\": "src/laravel-forge-api-php-sdk/" } }
Then run a composer update:, (*4)
composer update
In your code, require the Composer autoloader vendor/autoload.php
., (*5)
require __DIR__ . '/vendor/autoload.php';
Change the directory path to match your code's architecture if needed., (*6)
Create a new API Token from your Forge account settings., (*7)
Then copy and paste your API token into a Forge::setToken()
function and place
this inside your code., (*8)
Forge::setToken('COPY AND PASTE YOUR FORGE API TOKEN HERE');
Here are a few examples of what you can do. Server responses are in a JSON string format., (*9)
List all your servers:, (*10)
echo Servers::list();
Get information about a specific server:, (*11)
echo Servers::get($server_id);
List all your sites on a specific server:, (*12)
echo Sites::list($server_id);
Create a new server:, (*13)
Servers::create($payload); $payload = array( "provider" => $provider, // string "credential_id" => $credential_id, // boolean "region" => $region, // string "ip_address" => $ip_address, // string "private_ip_address" => $private_ip_address, // string "php_version" => $php_version, // string "database" => $database, // string "maria" => $maria, // boolean "load_balancer" => $load_balancer, // boolean "network" => $network // array );
Please visit our SDK API documentation for a complete reference of what classes and functions are available., (*14)
Servers::create($payload = [])
Servers::list()
Servers::get($server_id)
Servers::update($server_id)
Serverse::update_database_password($payload = [])
Servers::delete($server_id)
Servers::reboot($server_id)
Servers::revoke($server_id)
Servers::reconnect($server_id)
Servers::reactivate($server_id)
Services::reboot_mysql($server_id)
Services::stop_mysql($server_id)
Services::reboot_nginx($server_id)
Services::stop_nginx($server_id)
Services::reboot_postgres($server_id)
Services::stop_postgres($server_id)
Services::install_blackfire($payload = [])
Services::install_papertrail($payload = [])
Services::remove_papertrail($payload = [])
Daemons::create($server_id, $payload = [])
Daemons::list($server_id)
Daemons::get($server_id, $daemon_id)
Daemons::delete($server_id, $daemon_id)
Daemons::restart($server_id, $daemon_id)
FirewallRules::create($server_id, $payload = [])
FirewallRules::list($server_id)
FirewallRules::get($server_id, $rule_id)
FirewallRules::delete($server_id, $rule_id)
ScheduledJobs::create($server_id, $payload = [])
ScheduledJobs::list($server_id)
ScheduledJobs::get($server_id, $job_id)
ScheduledJobs::delete($server_id, $job_id)
MySQLDatabases::create($server_id, $payload = [])
MySQLDatabases::list($server_id)
MySQLDatabases::get($server_id, $database_id)
MySQLDatabases::delete($server_id, $database_id)
MySQLDatabaseUsers::create($server_id, $payload = [])
MySQLDatabaseUsers::list($server_id)
MySQLDatabaseUsers::get($server_id, $user_id)
MySQLDatabaseUsers::update($server_id, $user_id, $payload = [])
MySQLDatabaseUsers::delete($server_id, $user_id)
Sites::create($server_id, $payload = [])
Sites::list($server_id)
Sites::get($server_id, $site_id)
Sites::update($server_id, $site_id, $payload = [])
Sites::delete($server_id, $site_id)
Sites::balancing($server_id, $site_id, $payload = [])
SSLCertificates::create($server_id, $site_id, $payload = [])
SSLCertificates::install_existing($server_id, $site_id, $payload = [])
SSLCertificates::clone($server_id, $site_id, $payload = [])
SSLCertificates::letsencrypt($server_id, $site_id, $payload = [])
SSLCertificates::list($server_id, $site_id)
SSLCertificates::get($server_id, $site_id, $ssl_id)
SSLCertificates::install($server_id, $site_id, $ssl_id, $payload = [])
SSLCertificates::activate($server_id, $site_id, $ssl_id)
SSLCertificates::delete($server_id, $site_id, $ssl_id)
SSHKeys::create($server_id, $payload = [])
SSHKeys::list($server_id)
SSHKeys::get($server_id, $key_id)
SSHKeys::delete($server_id, $key_id)
Workers::create($server_id, $site_id, $payload = [])
Workers::list($server_id, $site_id)
Workers::get($server_id, $site_id, $worker_id)
Workers::delete($server_id, $site_id, $worker_id)
Workers::restart($server_id, $site_id, $worker_id)
Deployment::enable($server_id, $site_id)
Deployment::disable($server_id, $site_id)
Deployment::get_script($server_id, $site_id)
Deployment::update($server_id, $site_id, $payload = [])
Deployment::deploy($server_id, $site_id)
Deployment::reset($server_id, $site_id)
Deployment::get_log($server_id, $site_id)
ConfigurationFiles::get_nginx($server_id, $site_id)
ConfigurationFiles::update_nginx($server_id, $site_id, $payload = [])
ConfigurationFiles::get_env($server_id, $site_id)
ConfigurationFiles::update_env($server_id, $site_id, $payload = [])
GitProjects::install($server_id, $site_id, $payload = [])
GitProjects::remove($server_id, $site_id)
WordPress::install($server_id, $site_id, $payload = [])
WordPress::uninstall($server_id, $site_id)
Recipes::create($payload = [])
Recipes::list()
Recipes::get($recipe_id)
Recipes::get($recipe_id, $payload = [])
Recipes::delete($recipe_id)
Recipes::run($recipe_id, $payload = [])
Credentials::list()
Check out ../public/docs/index.php
for a complete reference of the SDK's
available API functions., (*15)
Check out ../public/docs/demo.php
for a live demo of more usage examples., (*16)
Use the framework set up in ../public/index.php
to test your code., (*17)
The SDK includes handlers for two of the most powerful PHP HTTP clients:, (*18)
By default, the Guzzle client is used to handle all Forge API requests., (*19)
If you desire to add other clients or change between clients, you can do so in a matter of seconds:, (*20)
Forge.php
const PHP_HTTP_CLIENT
on line 35 to the client you want.../HttpHandlers/
to make API requests.The SDK makes it easy to create and trigger custom exceptions in your code. Here's all you have to do:, (*21)
../Exceptions/Errors.php
.errors($id)
function array. The message ID may contain spaces and numbers.$data = [ //.. 'Custom Error ID 1' => ['context' => 'Your custom error message.' ], 'custom_error_id_2' => ['context' => 'Another custom error message.' ], //.. ];
get()
function of the Errors
base class like this:return Errors::get('Custom Error ID 1');
git checkout -b my-new-feature
)git commit -am 'Add some feature'
)git push origin my-new-feature
)To test your workflow, you can use my test repo., (*22)
Laravel Forge API SDK for PHP is released under the MIT License, (*23)
Buy me a few beers if you feel this SDK saved you a few jars of sweat or put a smile on your face. Cheers! ☺, (*24)
You can send Bitcoin donations to 1BM3kt5UKe4v6Rb8sQBXA9pnFgJdMGCwWq or via Coinbase by clicking on the button below., (*25)
Credit cards are also accepted here:, (*27)
[][flattr], (*29)
SDK for PHP for accessing the official Laravel Forge API
MIT