PHPackages                             denislam/laravel-forge-api-sdk-php - 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. denislam/laravel-forge-api-sdk-php

ActiveLibrary[API Development](/categories/api)

denislam/laravel-forge-api-sdk-php
==================================

SDK for PHP for accessing the official Laravel Forge API

16PHP

Since Sep 28Pushed 8y ago1 watchersCompare

[ Source](https://github.com/denislam/laravel-forge-api-sdk-php)[ Packagist](https://packagist.org/packages/denislam/laravel-forge-api-sdk-php)[ RSS](/packages/denislam-laravel-forge-api-sdk-php/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependenciesVersions (1)Used By (0)

Laravel Forge API SDK for PHP
=============================

[](#laravel-forge-api-sdk-for-php)

Automating tasks on Laravel Forge has never been so easy
--------------------------------------------------------

[](#automating-tasks-on-laravel-forge-has-never-been-so-easy)

The **Laravel Forge API SDK for PHP** makes it easy for developers to access [Laravel Forge](https://forge.laravel.com) in their PHP code via Forge's [official REST API](https://forge.laravel.com/api-documentation), 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](#installation) or by downloading a single zip or phar file from our [latest release](#).

- [Installation](#installation)
    - [Require the Composer Autoloader](#require-the-composer-autoloader)
    - [Set Your Forge API Token](#set-your-forge-api-token)
- [Usage](#usage)
    - [Functions Quick Reference](#functions-quick-reference)
    - [Complete Documentation](#complete-documentation)
    - [Live Demo](#live-demo)
    - [Code Sandbox](#code-sandbox)
- [Bonus Features](#bonus-features)
    - [Multiple HTTP Client Support](#multiple-http-client-support)
    - [Instant Dynamic HTTP Client Switching](#instant-dynamic-http-client-switching)
    - [Custom Exceptions Handling](#custom-exceptions-handling)
- [Am I Missing an Essential Feature?](#am-i-missing-an-essential-feature)
- [Contributing](#contributing)
- [License](#license)
- [Donate](#donate)

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

[](#installation)

The Laravel Forge API SDK for PHP can be installed via [Composer](http://getcomposer.org) by requiring the `guzzlehttp/guzzle` package (see: [GuzzleHTTP](http://guzzlephp.org)) and registering a PSR-4 autoloader for the `Laravel_Forge_API_PHP_SDK` namespace in your project's `composer.json`.

```
{
    "require": {
		"guzzlehttp/guzzle": "~6.0"
    },
	"autoload": {
		"psr-4": {
			"Laravel_Forge_API_PHP_SDK\\": "src/laravel-forge-api-php-sdk/"
	}
}

```

Then run a composer update:

```
composer update
```

### Require the Composer Autoloader

[](#require-the-composer-autoloader)

In your code, require the Composer autoloader `vendor/autoload.php`.

```
require __DIR__ . '/vendor/autoload.php';
```

Change the directory path to match your code's architecture if needed.

### Set Your Forge API Token

[](#set-your-forge-api-token)

Create a new API Token from your [Forge account settings](https://forge.laravel.com/user/profile#/api).

Then copy and paste your API token into a `Forge::setToken()` function and place this inside your code.

```
Forge::setToken('COPY AND PASTE YOUR FORGE API TOKEN HERE');
```

Usage
-----

[](#usage)

Here are a few examples of what you can do. Server responses are in a JSON string format.

List all your servers:

```
echo Servers::list();
```

Get information about a specific server:

```
echo Servers::get($server_id);
```

List all your sites on a specific server:

```
echo Sites::list($server_id);
```

Create a new server:

```
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
);
```

### Functions Quick Reference

[](#functions-quick-reference)

Please visit our [SDK API documentation](http://github.com/denislam/laravel-forge-api-php-sdk/wiki) for a complete reference of what classes and functions are available.

- Servers
    - `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
    - `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
    - `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)`
- Firewall Rules
    - `FirewallRules::create($server_id, $payload = [])`
    - `FirewallRules::list($server_id)`
    - `FirewallRules::get($server_id, $rule_id)`
    - `FirewallRules::delete($server_id, $rule_id)`
- Scheduled Jobs
    - `ScheduledJobs::create($server_id, $payload = [])`
    - `ScheduledJobs::list($server_id)`
    - `ScheduledJobs::get($server_id, $job_id)`
    - `ScheduledJobs::delete($server_id, $job_id)`
- MySQL Databases
    - `MySQLDatabases::create($server_id, $payload = [])`
    - `MySQLDatabases::list($server_id)`
    - `MySQLDatabases::get($server_id, $database_id)`
    - `MySQLDatabases::delete($server_id, $database_id)`
- MySQL Database Users
    - `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
    - `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 = [])`
- SSL Certificates
    - `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)`
- SSH Keys
    - `SSHKeys::create($server_id, $payload = [])`
    - `SSHKeys::list($server_id)`
    - `SSHKeys::get($server_id, $key_id)`
    - `SSHKeys::delete($server_id, $key_id)`
- Workers
    - `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
    - `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)`
- Configuration Files
    - `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 = [])`
- git Projects
    - `GitProjects::install($server_id, $site_id, $payload = [])`
    - `GitProjects::remove($server_id, $site_id)`
- WordPress
    - `WordPress::install($server_id, $site_id, $payload = [])`
    - `WordPress::uninstall($server_id, $site_id)`
- Recipes
    - `Recipes::create($payload = [])`
    - `Recipes::list()`
    - `Recipes::get($recipe_id)`
    - `Recipes::get($recipe_id, $payload = [])`
    - `Recipes::delete($recipe_id)`
    - `Recipes::run($recipe_id, $payload = [])`
- Credentials
    - `Credentials::list()`

### Complete Documentation

[](#complete-documentation)

Check out `../public/docs/index.php` for a complete reference of the SDK's available API functions.

### Live Demo

[](#live-demo)

Check out `../public/docs/demo.php` for a live demo of more usage examples.

### Code Sandbox

[](#code-sandbox)

Use the framework set up in `../public/index.php` to test your code.

Bonus Features
--------------

[](#bonus-features)

### Multiple HTTP Client Support

[](#multiple-http-client-support)

The SDK includes handlers for two of the most powerful PHP HTTP clients:

- [Guzzle 6](http://guzzlephp.org)
- [cURL 7](https://curl.haxx.se)

By default, the Guzzle client is used to handle all Forge API requests.

### Instant Dynamic HTTP Client Switching

[](#instant-dynamic-http-client-switching)

If you desire to add other clients or change between clients, you can do so in a matter of seconds:

1. Open `Forge.php`
2. Change `const PHP_HTTP_CLIENT` on line 35 to the client you want.
3. Save the file and you're done! The SDK will automatically use the HTTP client class located within `../HttpHandlers/` to make API requests.

### Custom Exceptions Handling

[](#custom-exceptions-handling)

The SDK makes it easy to create and trigger custom exceptions in your code. Here's all you have to do:

1. Open `../Exceptions/Errors.php`.
2. Enter your custom error reference ID and message into the ` 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.' ],
  //..
];
```

3. To return a custom error message in your code, simply use the `get()`function of the `Errors` base class like this:

```
return Errors::get('Custom Error ID 1');
```

4. That's it!

Am I Missing An Essential Feature?
----------------------------------

[](#am-i-missing-an-essential-feature)

- *Nothing is impossible!*
- [Open an issue](https://github.com/denislam/laravel-forge-api-php-sdk) and let's make the SDK better together!
- Bug reports, feature requests, fixes, and well-wishes are always welcome.
- Want to say thanks or buy me a beer? [Donations](#donations) are welcome. ☺

Contributing
------------

[](#contributing)

1. Create an issue and describe your idea.
2. [Fork it](https://github.com/denislam/laravel-forge-api-php-sdk/fork)
3. Create your feature branch (`git checkout -b my-new-feature`)
4. Commit your changes (`git commit -am 'Add some feature'`)
5. Publish the branch (`git push origin my-new-feature`)
6. Create a new Pull Request

*To test your workflow, you can use my [test repo](https://github.com/denislam/test-repo/).*

License
-------

[](#license)

Laravel Forge API SDK for PHP is released under the [MIT License](http://www.opensource.org/licenses/MIT)

Donate
------

[](#donate)

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! ☺

### Bitcoin

[](#bitcoin)

You can send Bitcoin donations to 1BM3kt5UKe4v6Rb8sQBXA9pnFgJdMGCwWq or via [Coinbase](https://blockchain.info/payment_request?address=1BM3kt5UKe4v6Rb8sQBXA9pnFgJdMGCwWq) by clicking on the button below.

[![coinbase](https://camo.githubusercontent.com/f13c80a420b8e29fc8c397b29f060540381a1ed37779d826bd22d62d3f32ce41/68747470733a2f2f626c6f636b636861696e2e696e666f2f5265736f75726365732f627574746f6e732f646f6e6174655f36342e706e67)](https://blockchain.info/payment_request?address=16opr7qrueNVi2sSKwTLF5VqyyuMX54H2T)

### PayPal

[](#paypal)

Credit cards are also accepted here:

[![PayPal](https://camo.githubusercontent.com/7b6de155df30b37b25eb5fec52f9213680c3dbf067dfb7d7e2850ac4096c7d05/68747470733a2f2f7777772e70617970616c6f626a656374732e636f6d2f656e5f55532f692f62746e2f62746e5f646f6e6174655f534d2e676966 "Donate with PayPal")](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=REBCNDWH2KWHJ)

### Flattr

[](#flattr)

[![flattr](https://camo.githubusercontent.com/41a1a68906b7f18eaf2c372bc091deadd3c688cc10a1db2ea9494180539265db/68747470733a2f2f627574746f6e2e666c617474722e636f6d2f666c617474722d62616467652d6c617267652e706e67 "Donate with Flattr")](https://flattr.com/submit/auto?fid=elv702&url=https%3A%2F%2Fgithub.com%2Fdenislam%2Flaravel-forge-api-php-sdk)

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/8c177d5b7cbb558264a376536c97ac28d47b65dbcfa6be32fcd58272544e0073?d=identicon)[denislam](/maintainers/denislam)

### Embed Badge

![Health badge](/badges/denislam-laravel-forge-api-sdk-php/health.svg)

```
[![Health](https://phpackages.com/badges/denislam-laravel-forge-api-sdk-php/health.svg)](https://phpackages.com/packages/denislam-laravel-forge-api-sdk-php)
```

###  Alternatives

[stripe/stripe-php

Stripe PHP Library

4.0k143.3M480](/packages/stripe-stripe-php)[twilio/sdk

A PHP wrapper for Twilio's API

1.6k92.9M272](/packages/twilio-sdk)[knplabs/github-api

GitHub API v3 client

2.2k15.8M187](/packages/knplabs-github-api)[facebook/php-business-sdk

PHP SDK for Facebook Business

90121.9M34](/packages/facebook-php-business-sdk)[meilisearch/meilisearch-php

PHP wrapper for the Meilisearch API

73813.7M114](/packages/meilisearch-meilisearch-php)[google/gax

Google API Core for PHP

263103.1M454](/packages/google-gax)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
