> ## Documentation Index
> Fetch the complete documentation index at: https://herd.laravel.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Laravel for Go

# How to set up a Laravel for Go application

Herd serves Laravel for Go applications just like your PHP sites. Every Laravel for Go application in a parked path is available via its `.test` domain, and Herd builds and starts it on demand when you open it in the browser. There are no commands to learn and no servers to keep running in a terminal.

## Requirements

Herd builds Laravel for Go applications with your Go installation. Open the settings, go to "Runtimes" → "Go" and click "Install". You can find all details on the [Go page](https://herd.laravel.com/docs/macos/technology/go.md).

## Creating an application

Herd ships with the Laravel installer, which creates Laravel for Go applications with the `--go` flag:

```bash theme={null}
cd ~/Herd
laravel new my-go-app --go
cd my-go-app
herd open
```

You can also create Laravel for Go applications in the new application window. Once Go is installed, the window lets you choose between PHP, Rust and Go. You can describe your idea in a prompt and let a coding agent [build it for you](https://herd.laravel.com/docs/macos/herd-studio/build-with-ai.md), or leave the prompt empty to create a fresh application.

![New application window with the choice between PHP, Rust and Go](https://mintcdn.com/herd/_gdap5T-1LhRYbu1/images/docs/new_application_go.png?fit=max\&auto=format\&n=_gdap5T-1LhRYbu1\&q=85\&s=669bc8012d91dfabcd4b8e0d16001319)

A new application connects to PostgreSQL by default. When Herd creates the application, it uses Herd's PostgreSQL service if you have one installed. Otherwise, it switches the application to SQLite and runs the migrations for you. If you create the application in your terminal, see [Using SQLite](#using-sqlite) to do the same yourself.

## Cloning an existing application

Click "Clone Repository" in the new application window to clone an existing Laravel for Go application. Herd recognizes the application by the `go.laravel.com` module in its `go.mod` and prepares a checklist for it. Herd installs Go if it's missing, generates the application key, runs the migrations and connects the services that the `.env` file asks for. If the application can't use the database that you pick yet, because its `bootstrap/app.go` doesn't list the driver, Herd tells you what to add.

If you clone the repository in your terminal instead, the application works as soon as it's in a parked path. Herd builds it on the first visit.

## How Herd serves Laravel for Go applications

Herd serves a site as a Laravel for Go application when its `go.mod` requires the `go.laravel.com` module. Other Go modules, like libraries or command line tools, aren't served. A site with a PHP front controller, like `artisan` or `public/index.php`, stays a PHP site even if it contains a `go.mod`.

When you open the site in your browser, Herd starts the application on a port of its own and nginx passes all requests for the `.test` domain to it:

* If the application has a `dev` script in its `package.json` and its `node_modules` are installed, Herd runs `laravel dev`. This starts the server, a queue worker and Vite. The server and the queue worker rebuild and restart when you change a `.go` file, `go.mod`, `go.sum` or `.env`, and Vite hot-reloads your frontend.
* Otherwise, Herd runs `go run .`.

The first start downloads the Go modules of the application and compiles it, which can take a minute. Your browser shows what the build is doing while you wait, and the full output if the build fails. After that, the application starts in a few seconds.

Herd stops the application when it didn't receive a request for five minutes, and starts it again with the next request. Laravel for Go applications run without [Herd Studio](https://herd.laravel.com/docs/macos/herd-studio/overview.md), so they also work if you turned it off.

> [!NOTE]
>
> If Herd runs your application with `go run .`, it doesn't pick up code changes on its own. Stop the application with `herd processes:stop app` or the stop button in the Applications window, and the next request builds and starts it again.

## Managing the application

The [Applications window](https://herd.laravel.com/docs/macos/sites/managing-sites.md) lists Laravel for Go applications with all your other sites. Instead of the PHP version, the inspector shows a "Dev server" row with the command that Herd runs and its current state. You can start, stop and restart the application there and look at its output.

You can do the same in your terminal. Run these commands in the application's directory:

```bash theme={null}
# Show the application, its command, its folder and its state
herd processes

# Show the output of the application and its build
herd processes:output app

# Stop and start the application
herd processes:stop app
herd processes:start app
```

## Running commands

Laravel for Go applications don't use `php artisan` or Composer. Run your console commands with the `laravel` CLI from the application's directory, which compiles the application first, or through Go:

```bash theme={null}
laravel migrate
laravel make:migration create_posts_table
laravel route:list

# The same with Go
go run . route:list
```

## Services

[Herd Pro](https://herd.laravel.com/checkout) users can connect their Laravel for Go applications to Herd's [services](https://herd.laravel.com/docs/macos/herd-pro-services/services.md). Select the application in the Applications window and pick a service in the "Services" section of the inspector, or use the `herd site:services` command. Herd writes the keys that Laravel for Go reads, like `DATABASE_URL` and `REDIS_URL`, to your `.env` file. Learn more in [Per-Site Services](https://herd.laravel.com/docs/macos/herd-pro-services/per-site-services.md#laravel-for-go).

Laravel for Go only connects to the databases whose driver the application lists in the `Drivers` of its `bootstrap/app.go`. Herd doesn't change your code, so make sure that the driver of your database is there:

| Database | Driver | Package |
| - | - | - |
| SQLite | `sqlite.Driver` | `go.laravel.com/db/sqlite` |
| MySQL, MariaDB | `mysql.Driver` | `go.laravel.com/db/mysql` |
| PostgreSQL | `postgres.Driver` | `go.laravel.com/db/postgres` |

After you add a driver, run `go mod tidy` to download its dependencies. Herd's other services, like Redis, Laravel Reverb, Meilisearch or MinIO, don't need any code changes. Laravel for Go has no driver for MongoDB.

When you copy the `.env` values of a service in the settings, a dropdown lets you choose between PHP, Rust and Go, and Herd shows the matching keys and the driver that a database needs.

### Using SQLite

The starter application uses PostgreSQL. To switch an application that you created in your terminal to SQLite, replace the PostgreSQL driver with the SQLite driver in `bootstrap/app.go`:

```go bootstrap/app.go theme={null}
import (
	// ...
	"go.laravel.com/db/sqlite"
)

// ...
Drivers: []db.Driver{sqlite.Driver},
```

Then point `DATABASE_URL` in your `.env` file at a SQLite database, download the driver's dependencies and run the migrations:

```bash theme={null}
# .env: DATABASE_URL=sqlite:storage/database.sqlite
go mod tidy
laravel migrate
```

## Testing emails

Laravel for Go sends emails with its SES mailer instead of SMTP. Herd's mail server accepts these emails as well, so you can [inspect them](https://herd.laravel.com/docs/macos/herd-pro-services/mail.md) like the emails of your PHP applications. Add these values to your `.env` file:

```bash .env theme={null}
MAIL_MAILER=ses
AWS_ENDPOINT_URL_SESV2=http://127.0.0.1:2304
AWS_DEFAULT_REGION=us-east-1
AWS_ACCESS_KEY_ID=herd
AWS_SECRET_ACCESS_KEY=secretkey
SES_CONFIGURATION_SET="${APP_NAME}"
```

Herd uses `SES_CONFIGURATION_SET` as the name of the inbox, like `MAIL_USERNAME` for PHP applications. The mailer needs the AWS credentials to sign its requests, but they don't have to be real ones. The port of `AWS_ENDPOINT_URL_SESV2` is the port of Herd's internal API server, which is `2304` by default. To copy the values for your machine, click the copy button in the toolbar of the Mails window and select "Copy for Go".

## HTTPS

You can [secure](https://herd.laravel.com/docs/macos/sites/securing-sites.md) a Laravel for Go application like any other site. When you do, Herd also updates the `vite.config` of the application, so Vite uses Herd's certificate and serves your assets via the site's domain instead of `http://localhost:5173`. When you unsecure the site, Herd restores the previous values. A running Vite restarts on its own.

## Herd Studio

[Herd Studio](https://herd.laravel.com/docs/macos/herd-studio/overview.md) works with Laravel for Go applications. Herd tells the coding agent that the site is a Laravel for Go application, which commands it runs with and which database drivers it needs, so the agent doesn't try to use `php artisan` or Composer. The Studio badge shows the application as the site's dev stack, where you can follow its output and start or stop it.

## Customizing how Herd starts the application

If your application lives in a subdirectory of your repository, or needs a different command, add an `app_server` section to the site's `herd.yml` file. See [Configuring app servers](https://herd.laravel.com/docs/macos/sites/herd-yaml.md#configuring-app-servers) for all options.
