• Stars
    star
    491
  • Rank 89,636 (Top 2 %)
  • Language
    PHP
  • License
    MIT License
  • Created almost 8 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

The official Laravel Forge PHP SDK.

Laravel Forge SDK

Build Status Total Downloads Latest Stable Version License

Introduction

The Laravel Forge SDK provides an expressive interface for interacting with Forge's API and managing Laravel Forge servers.

Official Documentation

Installation

To install the SDK in your project you need to require the package via composer:

composer require laravel/forge-sdk

Upgrading

When upgrading to a new major version of Forge SDK, it's important that you carefully review the upgrade guide.

Basic Usage

You can create an instance of the SDK like so:

$forge = new Laravel\Forge\Forge(TOKEN_HERE);

Using the Forge instance you may perform multiple actions as well as retrieve the different resources Forge's API provides:

$servers = $forge->servers();

This will give you an array of servers that you have access to, where each server is represented by an instance of Laravel\Forge\Resources\Server, this instance has multiple public properties like $name, $id, $size, $region, and others.

You may also retrieve a single server using:

$server = $forge->server(SERVER_ID_HERE);

On multiple actions supported by this SDK you may need to pass some parameters, for example when creating a new server:

$server = $forge->createServer([
    "provider"=> ServerProviders::DIGITAL_OCEAN,
    "credential_id"=> 1,
    "name"=> "test-via-api",
    "type"=> ServerTypes::APP,
    "size"=> "01",
    "database"=> "test123",
    "database_type" => InstallableServices::POSTGRES,
    "php_version"=> InstallableServices::PHP_71,
    "region"=> "ams2"
]);

These parameters will be used in the POST request sent to Forge servers, you can find more information about the parameters needed for each action on Forge's official API documentation.

Notice that this request for example will only start the server creation process, your server might need a few minutes before it completes provisioning, you'll need to check the server's $isReady property to know if it's ready or not yet.

Some SDK methods however wait for the action to complete on Forge's end, we do this by periodically contacting Forge servers and checking if our action has completed, for example:

$forge->createSite(SERVER_ID, [SITE_PARAMETERS]);

This method will ping Forge servers every 5 seconds and see if the newly created Site's status is installed and only return when it's so, in case the waiting exceeded 30 seconds a Laravel\Forge\Exceptions\TimeoutException will be thrown.

You can easily stop this behaviour by setting the $wait argument to false:

$forge->createSite(SERVER_ID, [SITE_PARAMETERS], false);

You can also set the desired timeout value:

$forge->setTimeout(120)->createSite(SERVER_ID, [SITE_PARAMETERS]);

Authenticated User

$forge->user();

Managing Servers

$forge->servers();
$forge->server($serverId);
$forge->createServer(array $data);
$forge->updateServer($serverId, array $data);
$forge->deleteServer($serverId);
$forge->rebootServer($serverId);

// Server access
$forge->revokeAccessToServer($serverId);
$forge->reconnectToServer($serverId);
$forge->reactivateToServer($serverId);

On a Server instance you may also call:

$server->update(array $data);
$server->delete();
$server->reboot();
$server->revokeAccess();
$server->reconnect();
$server->reactivate();
$server->rebootMysql();
$server->stopMysql();
$server->rebootPostgres();
$server->stopPostgres();
$server->rebootNginx();
$server->stopNginx();
$server->installBlackfire(array $data);
$server->removeBlackfire();
$server->installPapertrail(array $data);
$server->removePapertrail();
$server->enableOPCache();
$server->disableOPCache();
$server->phpVersions();
$server->installPHP($version);
$server->updatePHP($version);

Server SSH Keys

$forge->keys($serverId);
$forge->sshKey($serverId, $keyId);
$forge->createSSHKey($serverId, array $data, $wait = true);
$forge->deleteSSHKey($serverId, $keyId);

On a SSHKey instance you may also call:

$sshKey->delete();

Server Scheduled Jobs

$forge->jobs($serverId);
$forge->job($serverId, $jobId);
$forge->createJob($serverId, array $data, $wait = true);
$forge->deleteJob($serverId, $jobId);

On a Job instance you may also call:

$job->delete();

Server Events

$forge->events();
$forge->events($serverId);

Managing Services

// MySQL
$forge->rebootMysql($serverId);
$forge->stopMysql($serverId);

// Postgres
$forge->rebootPostgres($serverId);
$forge->stopPostgres($serverId);

// Nginx
$forge->rebootNginx($serverId);
$forge->stopNginx($serverId);
$forge->siteNginxFile($serverId, $siteId);
$forge->updateSiteNginxFile($serverId, $siteId, $content);

// Blackfire
$forge->installBlackfire($serverId, array $data);
$forge->removeBlackfire($serverId);

// Papertrail
$forge->installPapertrail($serverId, array $data);
$forge->removePapertrail($serverId);

// OPCache
$forge->enableOPCache($serverId);
$forge->disableOPCache($serverId);

Server Daemons

$forge->daemons($serverId);
$forge->daemon($serverId, $daemonId);
$forge->createDaemon($serverId, array $data, $wait = true);
$forge->restartDaemon($serverId, $daemonId, $wait = true);
$forge->deleteDaemon($serverId, $daemonId);

On a Daemon instance you may also call:

$daemon->restart($wait = true);
$daemon->delete();

Server Firewall Rules

$forge->firewallRules($serverId);
$forge->firewallRule($serverId, $ruleId);
$forge->createFirewallRule($serverId, array $data, $wait = true);
$forge->deleteFirewallRule($serverId, $ruleId);

On a FirewallRule instance you may also call:

$rule->delete();

Managing Sites

$forge->sites($serverId);
$forge->site($serverId, $siteId);
$forge->createSite($serverId, array $data, $wait = true);
$forge->updateSite($serverId, $siteId, array $data);
$forge->refreshSiteToken($serverId, $siteId);
$forge->deleteSite($serverId, $siteId);

// Add Site Aliases
$forge->addSiteAliases($serverId, $siteId, array $aliases);

// Environment File
$forge->siteEnvironmentFile($serverId, $siteId);
$forge->updateSiteEnvironmentFile($serverId, $siteId, $content);

// Site Repositories and Deployments
$forge->installGitRepositoryOnSite($serverId, $siteId, array $data, $wait = false);
$forge->updateSiteGitRepository($serverId, $siteId, array $data);
$forge->destroySiteGitRepository($serverId, $siteId, $wait = false);
$forge->siteDeploymentScript($serverId, $siteId);
$forge->updateSiteDeploymentScript($serverId, $siteId, $content);
$forge->enableQuickDeploy($serverId, $siteId);
$forge->disableQuickDeploy($serverId, $siteId);
$forge->deploySite($serverId, $siteId, $wait = false);
$forge->resetDeploymentState($serverId, $siteId);
$forge->siteDeploymentLog($serverId, $siteId);
$forge->deploymentHistory($serverId, $siteId);
$forge->deploymentHistoryDeployment($serverId, $siteId, $deploymentId);
$forge->deploymentHistoryOutput($serverId, $siteId, $deploymentId);

// PHP Version
$forge->changeSitePHPVersion($serverId, $siteId, $version);

// Installing Wordpress
$forge->installWordPress($serverId, $siteId, array $data);
$forge->removeWordPress($serverId, $siteId);

// Installing phpMyAdmin
$forge->installPhpMyAdmin($serverId, $siteId, array $data);
$forge->removePhpMyAdmin($serverId, $siteId);

// Updating Node balancing Configuration
$forge->updateNodeBalancingConfiguration($serverId, $siteId, array $data);

On a Site instance you may also call:

$site->refreshToken();
$site->delete();
$site->installGitRepository(array $data, $wait = false);
$site->updateGitRepository(array $data);
$site->destroyGitRepository($wait = false);
$site->getDeploymentScript();
$site->updateDeploymentScript($content);
$site->enableQuickDeploy();
$site->disableQuickDeploy();
$site->deploySite($wait = false);
$site->resetDeploymentState();
$site->siteDeploymentLog();
$site->getDeploymentHistory();
$site->getDeploymentHistoryDeployment($deploymentId);
$site->getDeploymentHistoryOutput($deploymentId);
$site->installWordPress($data);
$site->removeWordPress();
$site->installPhpMyAdmin($data);
$site->removePhpMyAdmin();
$site->changePHPVersion($version);
$site->siteLog();

Site Workers

$forge->workers($serverId, $siteId);
$forge->worker($serverId, $siteId, $workerId);
$forge->createWorker($serverId, $siteId, array $data, $wait = true);
$forge->deleteWorker($serverId, $siteId, $workerId);
$forge->restartWorker($serverId, $siteId, $workerId, $wait = true);

On a Worker instance you may also call:

$worker->delete();
$worker->restart($wait = true);

Security Rules

$forge->securityRules($serverId, $siteId);
$forge->securityRule($serverId, $siteId, $ruleId);
$forge->createSecurityRule($serverId, $siteId, array $data);
$forge->deleteSecurityRule($serverId, $siteId, $ruleId);

On a SecurityRule instance you may also call:

$securityRule->delete();

Site Webhooks

$forge->webhooks($serverId, $siteId);
$forge->webhook($serverId, $siteId, $webhookId);
$forge->createWebhook($serverId, $siteId, array $data);
$forge->deleteWebhook($serverId, $siteId, $webhookId);

On a Webhook instance you may also call:

$webhook->delete();

Site Commands

$forge->executeSiteCommand($serverId, $siteId, array $data);
$forge->listCommandHistory($serverId, $siteId);
$forge->getSiteCommand($serverId, $siteId, $commandId);

Site SSL Certificates

$forge->certificates($serverId, $siteId);
$forge->certificate($serverId, $siteId, $certificateId);
$forge->createCertificate($serverId, $siteId, array $data, $wait = true);
$forge->deleteCertificate($serverId, $siteId, $certificateId);
$forge->getCertificateSigningRequest($serverId, $siteId, $certificateId);
$forge->installCertificate($serverId, $siteId, $certificateId, array $data, $wait = true);
$forge->activateCertificate($serverId, $siteId, $certificateId, $wait = true);
$forge->obtainLetsEncryptCertificate($serverId, $siteId, $data, $wait = true);

On a Certificate instance you may also call:

$certificate->delete();
$certificate->getSigningRequest();
$certificate->install($wait = true);
$certificate->activate($wait = true);

Nginx Templates

$forge->nginxTemplates($serverId);
$forge->nginxDefaultTemplate($serverId);
$forge->nginxTemplate($serverId, $templateId);
$forge->createNginxTemplate($serverId, array $data);
$forge->updateNginxTemplate($serverId, $templateId, array $data);
$forge->deleteNginxTemplate($serverId, $templateId);

On a NginxTemplate instance you may also call:

$nginxTemplate->update(array $data);
$nginxTemplate->delete();

Managing Databases

$forge->databases($serverId);
$forge->database($serverId, $databaseId);
$forge->createDatabase($serverId, array $data, $wait = true);
$forge->updateDatabase($serverId, $databaseId, array $data);
$forge->deleteDatabase($serverId, $databaseId);
$forge->syncDatabases($serverId);

// Users
$forge->databaseUsers($serverId);
$forge->databaseUser($serverId, $userId);
$forge->createDatabaseUser($serverId, array $data, $wait = true);
$forge->updateDatabaseUser($serverId, $userId, array $data);
$forge->deleteDatabaseUser($serverId, $userId);

On a Database instance you may also call:

$database->update(array $data);
$database->delete();

On a DatabaseUser instance you may also call:

$databaseUser->update(array $data);
$databaseUser->delete();

Managing Recipes

$forge->recipes();
$forge->recipe($recipeId);
$forge->createRecipe(array $data);
$forge->updateRecipe($recipeId, array $data);
$forge->deleteRecipe($recipeId);
$forge->runRecipe($recipeId, array $data);

On a Recipe instance you may also call:

$recipe->update(array $data);
$recipe->delete();
$recipe->run(array $data);

Managing Backups

$forge->backupConfigurations($serverId);
$forge->createBackupConfiguration($serverId, array $data);
$forge->updateBackupConfiguration($serverId, $backupConfigurationId, array $data);
$forge->backupConfiguration($serverId, $backupConfigurationId);
$forge->deleteBackupConfiguration($serverId, $backupConfigurationId);
$forge->restoreBackup($serverId, $backupConfigurationId, $backupId);
$forge->deleteBackup($serverId, $backupConfigurationId, $backupId);

On a BackupConfiguration instance you may also call:

$extendedConfig = $backupConfig->get(); // Load the databases also
$backupConfig->update(array $data);
$backupConfig->delete();
$backupConfig->restoreBackup($backupId);
$backupConfig->deleteBackup($backupId);

On a Backup instance you may also call:

$backupConfig->delete();
$backupConfig->restore();

Managing Redirects

$forge->redirectRules($serverId, $siteId);
$forge->redirectRule($serverId, $siteId, $ruleId);
$forge->createRedirectRule($serverId, $siteId, array $data, $wait = true);
$forge->deleteRedirectRule($serverId, $siteId, $ruleId);

On a RedirectRule instance you may also call:

$redirectRule->delete();

Contributing

Thank you for considering contributing to Forge SDK! You can read the contribution guide here.

Code of Conduct

In order to ensure that the Laravel community is welcoming to all, please review and abide by the Code of Conduct.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

License

Laravel Forge SDK is open-sourced software licensed under the MIT license.

More Repositories

1

laravel

Laravel is a web application framework with expressive, elegant syntax. We’ve already laid the foundation for your next big idea β€” freeing you to create without sweating the small things.
PHP
75,490
star
2

framework

The Laravel Framework.
PHP
30,766
star
3

lumen

The Laravel Lumen Framework.
PHP
7,644
star
4

tinker

Powerful REPL for the Laravel framework.
PHP
7,241
star
5

socialite

Laravel wrapper around OAuth 1 & OAuth 2 libraries.
PHP
5,407
star
6

telescope

An elegant debug assistant for the Laravel framework.
PHP
4,631
star
7

homestead

Shell
3,850
star
8

jetstream

Tailwind scaffolding for the Laravel framework.
PHP
3,804
star
9

horizon

Dashboard and code-driven configuration for Laravel queues.
PHP
3,719
star
10

octane

Supercharge your Laravel application's performance.
PHP
3,533
star
11

passport

Laravel Passport provides OAuth2 server support to Laravel.
PHP
3,184
star
12

docs

The Laravel documentation.
2,816
star
13

sanctum

Laravel Sanctum provides a featherweight authentication system for SPAs and simple APIs.
PHP
2,623
star
14

pint

Laravel Pint is an opinionated PHP code style fixer for minimalists.
PHP
2,580
star
15

valet

A more enjoyable local development experience for Mac.
PHP
2,498
star
16

breeze

Minimal Laravel authentication scaffolding with Blade, Vue, or React + Tailwind.
PHP
2,469
star
17

ui

Laravel UI utilities and presets.
PHP
2,338
star
18

cashier-stripe

Laravel Cashier provides an expressive, fluent interface to Stripe's subscription billing services.
PHP
2,291
star
19

dusk

Laravel Dusk provides simple end-to-end testing and browser automation.
PHP
1,788
star
20

envoy

Elegant SSH tasks for PHP.
PHP
1,545
star
21

fortify

Backend controllers and scaffolding for Laravel authentication.
PHP
1,500
star
22

sail

Docker files for running a basic Laravel application.
Shell
1,468
star
23

lumen-framework

The Laravel Lumen Framework.
PHP
1,455
star
24

scout

Laravel Scout provides a driver based solution to searching your Eloquent models.
PHP
1,455
star
25

pulse

Laravel Pulse is a real-time application performance monitoring tool and dashboard for your Laravel application.
PHP
1,443
star
26

breeze-next

An application / authentication starter kit frontend in Next.js for Laravel Breeze.
JavaScript
1,116
star
27

reverb

Laravel Reverb provides a real-time WebSocket communication backend for Laravel applications.
PHP
1,095
star
28

echo

Laravel Echo library for beautiful Pusher and Ably integration.
TypeScript
1,085
star
29

elixir

Fluent API for Gulp.
JavaScript
1,080
star
30

settler

Shell
1,013
star
31

ideas

Issues board used for Laravel internals discussions.
943
star
32

slack-notification-channel

Slack Notification Channel for laravel.
PHP
829
star
33

vite-plugin

Laravel plugin for Vite.
TypeScript
783
star
34

helpers

Provides backwards compatibility for helpers in the latest Laravel release.
PHP
735
star
35

vonage-notification-channel

Vonage Notification Channel for Laravel.
PHP
709
star
36

pail

Dive into your Laravel application's log files directly from the console. πŸͺ£
PHP
564
star
37

folio

Page based routing for Laravel.
PHP
561
star
38

nova-issues

554
star
39

laravel.com

The source code of the official Laravel website.
Blade
531
star
40

installer

The Laravel application installer.
PHP
527
star
41

browser-kit-testing

Provides backwards compatibility for BrowserKit testing in the latest Laravel release.
PHP
497
star
42

serializable-closure

Laravel Serializable Closure provides an easy and secure way to serialize closures in PHP.
PHP
434
star
43

spark-legacy

PHP
428
star
44

pennant

A simple, lightweight library for managing feature flags.
PHP
408
star
45

vapor-core

The core service providers and runtime client for Laravel Vapor.
PHP
399
star
46

quickstart-basic

A sample task list application.
PHP
391
star
47

cashier-mollie

PHP
376
star
48

prompts

Beautiful and user-friendly forms for your command-line PHP applications.
PHP
357
star
49

spark-installer

PHP
314
star
50

nova-docs

The Laravel Nova documentation.
TypeScript
310
star
51

vapor-cli

The CLI client for interacting with Laravel Vapor.
PHP
303
star
52

vapor-ui

The Laravel Vapor UI.
Vue
265
star
53

quickstart-intermediate

A sample task list application with authentication.
PHP
262
star
54

blog-contest-may-mayhem

244
star
55

cashier-paddle

Cashier Paddle provides an expressive, fluent interface to Paddle's subscription billing services.
PHP
239
star
56

forge-cli

The Laravel Forge CLI.
PHP
219
star
57

spark-aurelius

PHP
202
star
58

art

Laravel logo and other artwork.
190
star
59

spark-tests

174
star
60

cashier-braintree

PHP
164
star
61

vapor-php-build

Dockerfile
132
star
62

nova-log-viewer

A Laravel Nova tool for viewing your application logs
PHP
118
star
63

legacy-factories

PHP
118
star
64

precognition

Anticipate the outcome of a future HTTP request.
TypeScript
115
star
65

nova-js

JavaScript
113
star
66

jetstream-js

JavaScript
107
star
67

forge-monitor

PHP
105
star
68

forge-database-backups

Shell
104
star
69

bootcamp.laravel.com

Laravel Bootcamp
PHP
98
star
70

nova-dusk-suite

PHP
93
star
71

vapor-laravel-template

PHP
86
star
72

lumen-docs

The Lumen documentation.
84
star
73

lumen-installer

PHP
76
star
74

jetstream-docs

The Jetstream documentation.
TypeScript
69
star
75

legacy-encrypter

PHP
60
star
76

.github

Source code of the default community health files for the Laravel organization.
52
star
77

vapor-dockerfiles

Dockerfile
49
star
78

vapor-docs

The Vapor documentation.
TypeScript
49
star
79

discord-bot

TypeScript
39
star
80

vapor-js

JavaScript
36
star
81

spark-aurelius-mollie

Laravel Spark, Mollie edition
PHP
28
star
82

spark-docs

The Spark Classic documentation.
27
star
83

nova-mix

JavaScript
26
star
84

envoyer-docs

The Envoyer documentation.
TypeScript
23
star
85

sail-server

The build website for new Laravel Sail apps.
PHP
19
star
86

facade-documenter

Laravel's Facade docblock generator.
PHP
15
star
87

spark-next-docs

The Spark documentation.
TypeScript
9
star