Laravel Forge API – Manage servers through the Forge API

Laravel Forge API is a powerful tool that allows you to manage your servers and applications through a RESTful API provided by Laravel Forge. Laravel Forge is a server management and deployment service for PHP applications that simplifies the process of provisioning and managing web servers. With the Forge API, developers can automate and manage their server infrastructure programmatically.

 

Key Features

  • Server Management: Create, update, and delete servers directly through the API.
  • Site Management: Manage your applications and sites hosted on your servers.
  • SSL Management: Easily handle SSL certificates for your applications.
  • Environment Variables: Manage environment variables for your applications.
  • Database Management: Create and manage databases for your applications.

Getting Started

1. Setup Laravel Forge

Before you can use the Laravel Forge API, you need to have a Laravel Forge account and at least one server set up.

2. Obtain an API Token

To authenticate requests to the Laravel Forge API, you need to generate an API token:

  1. Log in to your Laravel Forge account.
  2. Navigate to your account settings.
  3. Generate a new API token and keep it secure.

3. Making API Requests

You can use tools like Postman or any HTTP client (e.g., Guzzle) to interact with the Forge API. Here’s how to make basic API requests:

Example: Fetching All Servers

You can retrieve a list of all your servers using a GET request:

bash

Example Code Using Guzzle

Here’s an example of how to use Guzzle to fetch all servers:

php
 

Common API Endpoints

Here are some common endpoints you might use with the Laravel Forge API:

  1. List Servers:
    • GET /api/v1/servers
  2. Create a New Server:
    • POST /api/v1/servers
    • Payload: You will need to provide details like the server name, provider, region, etc.
  3. Delete a Server:
    • DELETE /api/v1/servers/{serverId}
  4. Manage Sites:
    • List all sites on a server: GET /api/v1/servers/{serverId}/sites
    • Create a site: POST /api/v1/servers/{serverId}/sites
    • Delete a site: DELETE /api/v1/servers/{serverId}/sites/{siteId}
  5. Manage SSL Certificates:
    • Add SSL: POST /api/v1/servers/{serverId}/sites/{siteId}/ssl
    • Remove SSL: DELETE /api/v1/servers/{serverId}/sites/{siteId}/ssl
  6. Environment Variables:
    • List environment variables: GET /api/v1/servers/{serverId}/sites/{siteId}/env
    • Update environment variables: PUT /api/v1/servers/{serverId}/sites/{siteId}/env

Example: Creating a New Server

To create a new server, you can send a POST request:

php
 

Conclusion

The Laravel Forge API provides a powerful way to manage your servers programmatically, making it easier to integrate server management into your development workflows. Whether you’re automating deployments, managing SSL certificates, or handling environment variables, the Forge API simplifies the process.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top