# Set up Relia in a Laravel or PHP app

> Add Relia to a Laravel app with one Composer package and one artisan command, or to plain PHP with two lines. No PHP extension needed.

Section: Set up your stack · Page: https://tryrelia.com/docs/laravel-php-setup · Last checked against the product: 2026-11-01
Video walkthrough: https://youtu.be/ZExvI3df3sE

Relia's PHP package is pure PHP. It needs no PHP extension, so it also works on shared hosting and cPanel. To have your AI assistant do the setup instead, see [Set up Relia with your AI assistant](https://tryrelia.com/docs/setup-with-ai-assistant.md).

## Before you start

- A Relia account ([Create your account](https://tryrelia.com/docs/create-account.md)).
- PHP 8.1 or newer, and Composer.
- Your project's id and key. In Relia, open your project and click **Setup Guide & SDK**, then pick **PHP / Laravel**. The code shown there already holds your id and your key (the key starts with `relia_live_`).

## Steps (Laravel)

1. **Install the package** in your Laravel app's folder:

   ```bash
   composer require tryrelia/relia
   ```

2. **Write the settings:**

   ```bash
   php artisan relia:install
   ```

   It asks for your project id, then your project key. Paste each one and press Enter. The **PHP / Laravel** card in the setup guide also shows this command with `--project`, `--key` and `--service` already filled in, so you can paste it instead.

3. **Check `.env`.** It now has three lines: `RELIA_PROJECT_ID`, `RELIA_KEY` and `RELIA_SERVICE_NAME`. There's no middleware or provider to add: Laravel picks the package up by itself.

4. **Add the browser part** (visitors, page speed and browser errors). Put this in your main Blade layout, just before `</head>`:

   ```blade
   @reliaScript
   ```

   If your app uses Vite, `relia:install` prints the lines to add to `resources/js/app.js` instead.

5. **Start your app and open any page.**

> **Tip:** if you have Node.js, `npx relia-sdk@latest init` in a Laravel app does all of this for you: it installs the Composer package, writes the `RELIA_*` lines to `.env` and wires the browser part through Vite.

## Steps (plain PHP)

1. **Install the package:**

   ```bash
   composer require tryrelia/relia
   ```

2. **Start Relia** at the top of your front controller (`public/index.php` or `index.php`), right after `<?php`:

   ```php
   require __DIR__ . '/vendor/autoload.php';
   \Relia\Relia::start(['projectId' => '<your project id>', 'serviceName' => 'shop', 'key' => '<your project key>']);
   ```

   Add the autoloader line only if the file doesn't load Composer yet. From `public/index.php` the path is `__DIR__ . '/../vendor/autoload.php'`.

Rather keep the values out of the code? Set `RELIA_PROJECT_ID`, `RELIA_KEY` and `RELIA_SERVICE_NAME` in your host's environment and call `\Relia\Relia::start()` with no arguments. Plain PHP doesn't read a `.env` file, so these must be real environment variables (your web server's or PHP-FPM pool's).

## What Relia records

In Laravel, from the next request:

- every request with its route (`/orders/{id}`), status and time;
- the error behind a 500, with its stack trace;
- database queries, with values removed;
- calls made with Laravel's HTTP client;
- queue jobs;
- warning and error log lines;
- the signed-in user's id (never the e-mail).

To show plans on people ("3 customers on Pro"), see [Identify your users](https://tryrelia.com/docs/identify-users.md).

> **Tip:** watch [See which customers a bug hit: identify users in Relia](https://youtu.be/1mIOiHnI9nk) (2 min).

In plain PHP: each request, uncaught exceptions and fatal errors. To time a slow part on its own:

```php
\Relia\Relia::measure('charge card', fn () => $gateway->charge($order));
```

The data is sent after the response, so visitors never wait for it (PHP-FPM and LiteSpeed). PHP's built-in server (`php artisan serve`, `php -S`) can't send the page first, so there each request waits a moment for the send. That's normal in development.

## Settings

All optional, in `.env`:

| Variable | What it does |
|---|---|
| `RELIA_SERVICE_NAME` | The name shown in Relia (default: your app's name) |
| `RELIA_ENV` | `development` on your laptop, so test traffic stays apart (default: Laravel's `APP_ENV`, else `production`) |
| `RELIA_LOGS=false` | Don't send log lines |
| `RELIA_LOG_LEVEL=error` | Only send errors |
| `RELIA_QUERIES=false`, `RELIA_HTTP_CLIENT=false`, `RELIA_QUEUE=false` | Switch one part off |
| `RELIA_RELEASE` | Your version, if Relia can't read it from git or your host |

## When you deploy

Add the same `RELIA_*` lines to your host's environment (Forge, Vapor, Laravel Cloud, cPanel and so on).

## Check it worked

Open your project in Relia and go to the **Setup** tab. **Requests from your server** changes from *Not yet* to *Arriving*. Your requests and errors appear under **APIs**, and your queries under **Database**.

## If something's wrong

- **`relia:install` says the id is wrong:** a project id is 24 letters and digits. Copy it again from the **Setup** tab.
- **The key is refused:** a project key starts with `relia_live_`.
- **No visits from the browser:** check that `@reliaScript` is in the layout your pages actually use, before `</head>`.
- **Still "Not yet":** see [Relia shows no data](https://tryrelia.com/docs/no-data.md).

## Next

- [Identify your users](https://tryrelia.com/docs/identify-users.md)
- [Teach Relia what matters](https://tryrelia.com/docs/teach-relia.md)
- [Choose how Relia reaches you](https://tryrelia.com/docs/notifications.md)

---
All Relia docs for AI assistants: https://tryrelia.com/llms.txt (index) · https://tryrelia.com/llms-full.txt (everything in one file)
