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

> Learn how to self-host Litlyx with Docker in a few steps.

# Self-host with Docker

## 1. Clone the Workspace

Clone or fork the Litlyx repository from GitHub to your local machine.
Open the file `docker-compose.yaml`.

## 2. Update MongoDB Credentials

In the `mongo` service, update the following fields with your preferred
username and password:

```yaml theme={null}
  MONGO_INITDB_ROOT_USERNAME: root        # change this
  MONGO_INITDB_ROOT_PASSWORD: mongo_pass  # change this
```

Update the MongoDB connection string in both `producer` and `consumer`
services:

```bash theme={null}
  MONGO_CONNECTION_STRING=mongodb://root:mongo_pass@mongo:27017/Litlyx?authSource=admin
```

Update the same value in the `dashboard` service:

```bash theme={null}
  NUXT_MONGO_CONNECTION_STRING=mongodb://root:mongo_pass@mongo:27017/Litlyx?authSource=admin
```

## 3. Update Redis Credentials

In the `redis` service, change the following fields:

```yaml theme={null}
  command: ["redis-server", "--requirepass", "redis_pass"]
  REDIS_PASSWORD: redis_pass
```

These values must match exactly.\
Note: `REDIS_USERNAME` must remain the default one.

Update Redis credentials in `producer` and `consumer`:

```yaml theme={null}
  REDIS_PASSWORD: redis_pass
```

Update Redis credentials in `dashboard`:

```bash theme={null}
  NUXT_REDIS_PASSWORD=redis_pass
```

## 4. Set the Authentication JWT Secret

In the `dashboard` service, set your session secret:

```bash theme={null}
  NUXT_SESSION_PASSWORD=jwt_secret_here
```

This is required to keep your Nuxt instance secure.

## 5. Update Admin Credentials

Litlyx includes symbolic default admin credentials.\
Replace them to keep your instance secure.

```yaml theme={null}
  NUXT_ADMIN_EMAIL=your_admin_email
  NUXT_ADMIN_PASSWORD=your_admin_password
```

## 6. Start the Docker Containers

Prepare your docker images by running this command:

<CodeGroup>
  ```bash npm theme={null}
  npm run docker-prepare
  ```

  ```bash yarn theme={null}
  yarn run docker-prepare
  ```

  ```bash pnpm theme={null}
  pnpm run docker-prepare
  ```

  ```bash bun theme={null}
  bun run docker-prepare
  ```
</CodeGroup>

Than run this command to start the containers:

```bash theme={null}
docker-compose up
```

Docker will automatically download and start all Litlyx services from **Docker Hub**.

<Note>
  Litlyx depends on `ts-node`... so make sure you've that installed in your instance. Run `npm install ts-node`.
</Note>

## 6.a Forward Data with a Script Tag

To forward data from your website to your instance, configure the script
with:

* `data-host`
* `data-port`
* `data-secure` → `true` for HTTPS, `false` for HTTP

Open the following ports:

* `3000` for the dashboard
* `3001` for incoming events

```html theme={null}
<script 
  defer
  data-workspace="workspace_id"
  data-host="your-host"
  data-port="your-producer-port"
  data-secure="false"
  src="https://cdn.jsdelivr.net/npm/litlyx-js@latest/browser/litlyx.js">
</script>
```

<Note>
  The Producer service collects events and queues them for storage.
  Default port: 3001, but customizable.
</Note>

## 6.b Forward Data Using NPM

If using NPM:

```javascript theme={null}
Lit.init("workspace_id", {
  server: {
    host: "your-host",
    port: 3001,
    secure: true
  }
})
```

<Note>
  The Producer service queues data before storage. Default port: 3001.
</Note>

## 7. Enable AI Features (Optional)

To enable Reports and AI Chat in the dashboard, set these fields:

```yaml theme={null}
  NUXT_PUBLIC_AI_ENABLED=true
  NUXT_AI_ORG=your_openai_org_id
  NUXT_AI_PROJECT=your_openai_project_id
  NUXT_AI_KEY=your_openai_api_key
```

These values are available in your [OpenAI admin console](https://platform.openai.com).

## 8. Now is your turn.

Now you are up to go. You can use your own instance of Litlyx. Track analytics, easy way.

<img className="block dark:hidden" src="https://mintcdn.com/litlyx/ZRsr_0gRAjVQ3hFD/images/easy-dashboard.svg?fit=max&auto=format&n=ZRsr_0gRAjVQ3hFD&q=85&s=93092cdd836167ce14aff71e709a7b00" alt="Hero Light" width="1053" height="558" data-path="images/easy-dashboard.svg" />

<img className="hidden dark:block" src="https://mintcdn.com/litlyx/ZRsr_0gRAjVQ3hFD/images/easy-dashboard.svg?fit=max&auto=format&n=ZRsr_0gRAjVQ3hFD&q=85&s=93092cdd836167ce14aff71e709a7b00" alt="Hero Dark" width="1053" height="558" data-path="images/easy-dashboard.svg" />
