# Run an app or a database

> Deploy your code from git with Apps, run a PostgreSQL database on Container Apps, and connect the two, from start to finish.

Source: https://www.coritan.com/docs/get-started/run-an-app-or-a-database/

In the dashboard:

- /dashboard/apps: https://www.coritan.com/dashboard/apps
- /dashboard/apps/new: https://www.coritan.com/dashboard/apps/new
- /dashboard/apps/…/deployments: https://www.coritan.com/dashboard/apps
- /dashboard/apps/…/domains: https://www.coritan.com/dashboard/apps
- /dashboard/apps/…/environment: https://www.coritan.com/dashboard/apps
- /dashboard/order: https://www.coritan.com/dashboard/order
- /dashboard/order/managed-containers: https://www.coritan.com/dashboard/order/managed-containers
- /dashboard/servers/…/console: https://www.coritan.com/dashboard/servers
- /dashboard/servers/…/settings: https://www.coritan.com/dashboard/servers

This tutorial gets your own code running on Coritan with a database beside it. Two products do the work. [Apps](/docs/apps/) builds your app from a git repository and serves it over HTTPS, at its own address and on your domain. [Container Apps](/docs/managed-containers/) runs one program from a catalogue on a server of its own, here a PostgreSQL database. Sections 1 to 3 deploy the app, sections 4 and 5 run the database, and section 6 connects them. To run only a database, start at section 4.

An app has no plan and no invoice ([How Apps is billed](/docs/apps/#how-apps-is-billed)). The database server costs the plan you choose on its order page. If you are not sure which product suits your code, read [Container Apps, Cloud Compute and Apps compared](/docs/learn/choose-a-compute-product/) first.

## Before you begin

- A Coritan account. [Create an account](/docs/get-started/create-an-account/) if you have none, then sign in.
- Your app in a git repository on a public host, such as GitHub, that answers over HTTPS. For a private repository, an access token from your git host that can read it.
- An app that listens on the port in its `PORT` variable and answers HTTP requests for `/` ([What your app must do](/docs/apps/how-apps-work/#what-your-app-must-do)).
- For the database, credit for the server's first invoice, or a card or PayPal to pay it when you order ([Add credit to your balance](/docs/billing/add-credit/)).
- `psql`, PostgreSQL's command-line client, on your computer.

## 1. Create the app

1. In the dashboard, go to [Apps](https://www.coritan.com/dashboard/apps) and select **New app…**.
2. Under **App**, type a **Name**, such as `Web shop`. The hint under it shows the address the app will answer at.
3. Under **Source**, choose **Git repository**. Fill in **Repository** with the repository's HTTPS address, such as `https://github.com/example/web-shop`, and change **Branch** when the app is not on `main`. Fill in **Access token** when the repository is private.
4. Under **Regions**, leave **Every region** chosen, and **Replicas per region** at `1`.
5. Under **Run**, set **Health check path** to a path your app answers, `/` at first, and choose a **Size**.
6. Leave **Start the first deployment now** ticked, and select **Create app**.
7. In the **Push webhook secret** dialog, select **Copy all** and keep what it copies, then select **I have saved it**. You need it only to deploy on every push ([Deploy on every push](/docs/apps/push-webhook/)).

The first deployment's page opens, and its **Build log** follows the build ([Create an app](/docs/apps/create-an-app/)).

> [!NOTE]
> The sidebar has no **Apps** while Apps is off for the platform. You can then run the app on a Container Apps server. Select **Node.js app** under **Quick start** on the [Order a service](https://www.coritan.com/dashboard/order) page, or choose **Python** under **Runtimes** in the order page's **Software** section. Under **Source**, fill in **Git repository**, and **Entry file** when the app does not start from `index.js` or `main.py`. The server clones the repository when it installs the software, and the app listens on the port in its `SERVER_PORT` variable ([Order a server](/docs/managed-containers/order-a-server/#choose-the-software)).

## 2. Watch it go live

Coritan builds an image from your branch, then starts the replicas and requests your health check path on each one. The deployment's progress bar says what it is doing, such as `Building` or `Starting replicas`.

Once the deployment is **Ready**, the app is **Live**. Open its platform address, such as `https://web-shop.apps.example.net`, which the app's header shows with a copy button. Your app answers over HTTPS ([Read a deployment and its build log](/docs/apps/read-a-deployment/)).

## 3. Serve it on your domain

1. On the app's page, select the **Domains** tab, then **Add domain…**.
2. In **Domain**, type the name, such as `www.example.com`, and select **Add domain**.
3. At your DNS host, create the `TXT` record that **Prove the domain is yours** gives, and the `CNAME` record that **Send its visitors to the app** gives. When Coritan hosts the domain's DNS, add both on the domain's **DNS** tab ([Add, edit and delete DNS records](/docs/websites/dns/manage-dns-records/)).
4. Wait a few minutes, then select **Verify** on the domain's row.

The domain shows **Verified**, and `Certificate issued` once the certificate authority has checked it. Your app answers at `https://www.example.com` ([Add a custom domain](/docs/apps/custom-domains/)).

## 4. Order the database server

1. In the dashboard, go to [Order a service](https://www.coritan.com/dashboard/order) and select **PostgreSQL database** under **Quick start**. The Container Apps order page opens with PostgreSQL chosen under **Software**.
2. Under **Plan**, choose how often to pay, then a plan under **Size**.
3. Under **Version**, keep the version the page chose, marked `Default`, or choose the major version your app needs.
4. Under **Location**, choose the data centre closest to the people who use your app.
5. Under **Settings**, keep the suggested **Server name** or type your own. You can rename the server later on its **Settings** tab ([Rename the server](/docs/managed-containers/settings/#rename-the-server)).
6. Check the summary under **Your order**, then select the button under it. It reads **Deploy server** when your credit pays the first invoice, and **Place order and pay** when you pay on the next page.
7. If the order's page reads **Order placed, payment due**, pay under **Pay invoice**.

The order's page shows **Setting up**, then **Your order is ready**. The server appears on the [Container Apps](https://www.coritan.com/dashboard/servers) page with the status `Installing` while Coritan installs PostgreSQL ([Order a server](/docs/managed-containers/order-a-server/)).

## 5. Start the database and connect to it

1. Open the server from the **Container Apps** page. The install does not start it, so select **Start**. The console shows PostgreSQL's own messages until it prints `database system is ready to accept connections` ([Use the console and power controls](/docs/managed-containers/console/)).
2. Select the **Settings** tab. Under **Network**, **Address with port** shows where the database listens, such as `203.0.113.10:10565`, and **Copy address** copies it.
3. Under **Startup variables**, read the user name in `POSTGRES_USER`, the password in `POSTGRES_PASSWORD` and the database's name in `POSTGRES_DB` ([Server settings](/docs/managed-containers/settings/#startup-variables)).
4. On your computer, connect with `psql` and the values from the tab, then type the password when it asks:

   ```bash
   psql -h 203.0.113.10 -p 10565 -U pguser pgdb
   ```

5. At the `pgdb=#` prompt, give the user a password of your own:

   ```text
   \password pguser
   ```

> [!WARNING]
> Every new PostgreSQL server starts with the same password, the one **Startup variables** shows, and the server's address is public. Set your own before you store anything. The table goes on showing the first password, so keep the new one somewhere safe.

`psql` connects and shows its prompt, and after `\password` it connects only with your new password.

## 6. Connect the app to the database

1. Open the app from [Apps](https://www.coritan.com/dashboard/apps) and select the **Environment** tab, then **Add variable…**.
2. In **Name**, type the variable your app reads, such as `DATABASE_URL`. In **Value**, type the connection address, such as `postgresql://pguser:YOUR_PASSWORD@203.0.113.10:10565/pgdb`, with your new password in it.
3. Leave **Secret** ticked, choose **Runtime only** in **Available at**, and select **Add variable**.
4. Select **Redeploy…** in the app's header, then **Redeploy**. Replicas keep the variables they started with until the next deployment.

The new deployment's page opens. Once it is **Ready**, your app reads `DATABASE_URL` and stores its data in PostgreSQL ([Set environment variables](/docs/apps/environment-variables/)).

## Troubleshooting

`The app did not pass its health check within 10 minutes. Health check on /: the connection failed`
: Nothing answered on the port in the app's `PORT` variable. Make the app listen on that port ([Replicas do not pass their health check](/docs/apps/troubleshooting/#replicas-do-not-pass-their-health-check)).

`Not verified yet` under the domain's row
: Coritan did not find the `TXT` record. Check its name and value at your DNS host, wait a few minutes, then select **Verify** again.

`psql` cannot connect
: Check that the server's status badge says it is running, and that `psql` uses the port from **Address with port** rather than PostgreSQL's usual `5432` ([Troubleshoot servers](/docs/managed-containers/troubleshooting/)).

## Next steps

- [Deploy on every push](/docs/apps/push-webhook/), so each push to the branch goes live
- [Take a server snapshot](/docs/managed-containers/snapshots/) of the database server before a risky change
- [Store files and backups](/docs/get-started/store-files-and-backups/), for the files your app keeps outside the database
