# Connecting local database via ngrok

If you need to connect your local database but you don’t want to use the on-premise version, you can go for the option of connecting via [ngrok.](https://ngrok.com)

{% hint style="info" %}
If your database is hosted locally or is not accessible from external connections, we recommend using our **on-premise** version. You can set it up easily with a single command:

`curl -k -L -o install.sh https://raw.githubusercontent.com/uibakery/self-hosted/main/install.sh && bash ./install.sh`

Additionally, during the installation process, you will have the option to generate a trial license.

Alternatively, if on-premise installation is not an option, you may try setting up an [SSH tunnel to your database](/concepts/data-sources/ssh-tunneling.md).
{% endhint %}

:exclamation:We highly recommend the *ngrok* approach for <mark style="color:red;">**testing purposes**</mark> only, as ngrok is a third-party proxy that provides only a temporary connection (40-120 minutes depending on your plan), and re-connection is required.

## **To connect your local database via ngrok:**

1. Create an account at [ngrok](https://ngrok.com) if you do not have one.
2. [Download ngrok](https://ngrok.com/download).
3. Unzip the archive (initial instruction can be found [here](https://dashboard.ngrok.com/get-started/setup)).
4. Open your **Terminal** (MacOS/Linux) or **command line** (Windows) and navigate to the **Downloads** folder (or the folder where the ngrok archive has been saved). Use the following command:\
   &#x20;`cd Downloads`
5. Next, you need to add your authtoken to the default **ngrok.yml** configuration file using this command:

`ngrok config add-authtoken 2qO7FgeP0PKr4eigzL2tdAJsxt8_3tBf8bHFrUiNZgdCEDvrc`

{% hint style="info" %}
You can find your personal token on the [authtoken page](https://dashboard.ngrok.com/get-started/your-authtoken). The token will look like this:\
`20JWDkD3uwe2wuRqhCvuTkQ0LE3_5N6KtiEBDLD3fXZkRHpej`
{% endhint %}

6. If successful, you’ll get the following message: \
   `Authtoken saved to configuration file: /Users/user_name/.ngrok2/ngrok.yml`
7. Now, you can proceed with exposing your local app server or database.\
   Use one of these commands :

```
app server: ./ngrok http 80 (or port your server is hosted on)
mysql: ./ngrok tcp 3306
postgre: ./ngrok tcp 5432
mssql: ./ngrok tcp 1433
mongodb: ./ngrok tcp 27017
```

The output will list a forwarding URL, which will point to your local server - find the **Forwarding line** and copy the host and the port.

8. Next, navigate to **UI Bakery** > **Connect datasource.**
9. Select your data source and specify the copied host and port together with the other database details.
10. Click **Test connection** to check whether the connection can be established.
11. And finally, click **Connect Datasource.**


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.uibakery.io/concepts/data-sources/connecting-local-database-via-ngrok.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
