# Laravel Horizon on a Mac

> Keep Laravel Horizon, queue:work and the scheduler running on macOS with Homebrew’s Supervisor: the configs, the PHP path fix, restarts after code changes.

Source: https://getvisor.dev/guides/laravel-horizon-mac/
Author: Touhidur Rahman (https://touhidurabir.github.io/)

`php artisan horizon` and `php artisan queue:work` stop when you close the terminal they run in. On a Mac, Supervisor (supervisord) from Homebrew keeps them running in the background, restarts them when they crash and starts them again when you log in. This guide sets that up for one Laravel app, with plain config files, then shows the same in Visor.

The examples use an app called `acme` in `/Users/you/Sites/acme`. Change the names and paths to yours.

## What you need

- Homebrew, PHP and a Laravel app.
- Redis, for Horizon. Install it and start it at login:

  ```sh
  brew install redis
  brew services start redis
  ```

- Horizon in the app:

  ```sh
  composer require laravel/horizon
  php artisan horizon:install
  ```

A queue worker without Horizon can use the `database` queue driver and skip Redis.

## Install Supervisor

```sh
brew install supervisor
brew services start supervisor
```

`brew services` runs supervisord as you, at every login, with Homebrew’s config. Check that it answers:

```sh
supervisorctl status
```

With no programs yet it prints nothing. An error such as `unix:///…/supervisor.sock no such file` means supervisord isn’t running; see [supervisor.sock: no such file](https://getvisor.dev/guides/supervisor-sock-no-such-file/).

Each program gets its own `.ini` file in Homebrew’s include folder, `$(brew --prefix)/etc/supervisor.d/`: `/opt/homebrew/etc/supervisor.d/` on Apple Silicon, `/usr/local/etc/supervisor.d/` on Intel. [Install on macOS](https://getvisor.dev/docs/install-macos/#if-supervisord-isnt-installed) lists the rest of Homebrew’s paths.

## Use the full path to PHP

This is the step most setups miss. supervisord started by `brew services` gets macOS’s short default `PATH`, `/usr/bin:/bin:/usr/sbin:/sbin`, which has no Homebrew and no Herd. A `command=` that starts with plain `php` fails with:

```text
acme-horizon                     FATAL     can't find command 'php'
```

Find your PHP and use that path in every `command=`:

```sh
which php
```

It’s usually `/opt/homebrew/bin/php` on Apple Silicon or `/usr/local/bin/php` on Intel. With Laravel Herd it’s inside `/Users/you/Library/Application Support/Herd/bin/`. That path has a space, so put it in double quotes in `command=`:

```ini
command="/Users/you/Library/Application Support/Herd/bin/php" artisan horizon
```

## Run Horizon

Create `$(brew --prefix)/etc/supervisor.d/acme-horizon.ini`:

```ini
[program:acme-horizon]
command=/opt/homebrew/bin/php artisan horizon
directory=/Users/you/Sites/acme
autostart=true
autorestart=true
stopwaitsecs=3600
redirect_stderr=true
stdout_logfile=/Users/you/Sites/acme/storage/logs/horizon.log
```

- `directory=` is the app’s folder, so `artisan` is found.
- `autorestart=true` starts Horizon again whenever it exits.
- `stopwaitsecs=3600` gives running jobs up to an hour to finish when you stop Horizon, before supervisord kills it. Set it a little above your longest job. [Every supervisord option, explained](https://getvisor.dev/guides/supervisord-config-options/) covers each line in more depth.
- There’s no `user=` line. [Laravel’s docs](https://laravel.com/docs/horizon#deploying-horizon) show `user=forge` for a server, where supervisord runs as root. Here it already runs as you, and `user=` works only for root.

Load the file and check it:

```sh
supervisorctl update
supervisorctl status
```

`update` reads the config again and starts what’s new. `status` should show:

```text
acme-horizon                     RUNNING   pid 41870, uptime 0:00:06
```

## Queue workers without Horizon

For `queue:work`, run a few copies from one file, `acme-queue.ini`:

```ini
[program:acme-queue]
command=/opt/homebrew/bin/php artisan queue:work --sleep=3 --tries=3 --max-time=3600
directory=/Users/you/Sites/acme
process_name=%(program_name)s_%(process_num)02d
numprocs=2
autostart=true
autorestart=true
stopasgroup=true
killasgroup=true
stopwaitsecs=3600
redirect_stderr=true
stdout_logfile=/Users/you/Sites/acme/storage/logs/queue.log
```

`numprocs=2` starts two workers, named `acme-queue:acme-queue_00` and `acme-queue:acme-queue_01`. `--max-time=3600` makes each worker exit after an hour, and supervisord starts a fresh one, which keeps memory in check. `stopasgroup` and `killasgroup` stop anything a worker started, too.

Run Horizon or `queue:work` for a queue, not both.

## The scheduler

Laravel’s scheduler fits here too:

```ini
[program:acme-scheduler]
command=/opt/homebrew/bin/php artisan schedule:work
directory=/Users/you/Sites/acme
autostart=true
autorestart=true
stopwaitsecs=60
redirect_stderr=true
stdout_logfile=/Users/you/Sites/acme/storage/logs/scheduler.log
```

Use `schedule:work`, which stays in the foreground and runs your schedule every minute. `schedule:run` exits after one pass, so supervisord reports it as [FATAL Exited too quickly](https://getvisor.dev/guides/exited-too-quickly/).

## After you change code

Horizon and queue workers load your code once, when they start. After you change a job, a listener or a config value, restart them:

```sh
php artisan horizon:terminate
php artisan queue:restart
```

Both let the current job finish, then exit. supervisord starts them again with the new code. `supervisorctl restart acme-horizon` or `supervisorctl restart acme-queue:*` does it at once, without waiting.

## If it won’t start

`supervisorctl status` says why:

- `can't find command 'php'`: use the full path, as above.
- `Exited too quickly (process log may have details)`: Horizon started and stopped straight away. Read why with `supervisorctl tail acme-horizon`. Redis not running is the usual reason. [FATAL Exited too quickly](https://getvisor.dev/guides/exited-too-quickly/) has the rest.
- `ERROR (no such process)`: supervisord hasn’t loaded the file. Run `supervisorctl update`, and check that the file ends in `.ini` and sits in the include folder.

## With Visor

Visor puts the same setup in the menu bar. Click **Add new**, choose **Fill a form**, and start from the **Laravel Horizon**, **Laravel queue worker** or **Laravel scheduler** template. The templates use `php artisan …` and placeholder paths under `/srv/acme`: set the directory to your app, and `php` to the full path from `which php`. **Save & apply** writes the file and loads it, like `supervisorctl update`. See [Program configs](https://getvisor.dev/docs/configs/).

From then on, the popover shows whether Horizon and the workers are running. A worker that keeps crashing opens an issue and can notify you (see [Issues and notifications](https://getvisor.dev/docs/issues/)). **Restart** is one click, and the logs follow live (see [Processes and logs](https://getvisor.dev/docs/processes/)).