---
title: "Deploy YOURLS on Pethost in one click"
description: "Your own URL shortener with click stats. A template for Pethost: in a minute or two the app is live on your machine, with HTTPS at its own address and nightly backups."
---

[← All templates](https://pethost.dev/templates/)

# Deploy YOURLS on Pethost in one click

Your own URL shortener with click stats

[Deploy on Pethost](https://console.pethost.dev/?template=yourls)

## What happens

1. You sign in to Pethost or make an account, with a passkey, GitHub or Google.
2. No machine yet? You pick a plan, and we prepare one for you. The link waits in your browser until it is ready.
3. New project opens at the app. You fill in what it asks for and click Create project: **Username**, **Admin password**.
4. In a minute or two the app is live at its own address with HTTPS. Its secrets are made for it at random, and its data is in the nightly backup.
5. It is a project like any other: its compose.yaml, its .env, its logs and a terminal are in the panel, and your agent can change it, roll it back or restore it.

## First steps

Sign in at https://yourls.sam.pethost.app/admin/ with the username and password you gave; short links answer at https://yourls.sam.pethost.app/<keyword>. The password is read from the project’s .env at every start: to change it, edit .env and deploy again.

## What it runs

The template is this compose.yaml and the variables it writes into the project’s .env. Pethost runs the file as it is written.

```
services:
  yourls:
    image: yourls:1.10.6-apache
    restart: unless-stopped
    environment:
      YOURLS_SITE: ${URL}
      YOURLS_USER: ${ADMIN_USERNAME}
      YOURLS_PASS: ${ADMIN_PASSWORD}
      YOURLS_COOKIEKEY: ${COOKIE_KEY}
      YOURLS_DB_HOST: db
      YOURLS_DB_USER: yourls
      YOURLS_DB_PASS: ${DB_PASSWORD}
      YOURLS_DB_NAME: yourls
    # The image runs the PHP files of /docker-entrypoint-init.d before Apache starts: this one
    # waits for the database and makes YOURLS's tables, which its install page would otherwise
    # leave to a visitor's click.
    command:
      - sh
      - -c
      - |
        mkdir -p /docker-entrypoint-init.d
        cat > /docker-entrypoint-init.d/install.php <<'PHP'
        <?php
        for ($$try = 0; $$try < 60; $$try++) {
            try {
                new PDO('mysql:host=' . getenv('YOURLS_DB_HOST') . ';dbname=' . getenv('YOURLS_DB_NAME'), getenv('YOURLS_DB_USER'), getenv('YOURLS_DB_PASS'));
                break;
            } catch (PDOException $$e) {
                sleep(2);
            }
        }
        define('YOURLS_ADMIN', true);
        define('YOURLS_INSTALLING', true);
        require '/var/www/html/includes/load-yourls.php';
        if (!yourls_is_installed()) {
            $$result = yourls_create_sql_tables();
            if (!empty($$result['error'])) {
                fwrite(STDERR, implode("\n", $$result['error']) . "\n");
                exit(1);
            }
        }
        PHP
        exec container-entrypoint.sh apache2-foreground
    depends_on:
      db:
        condition: service_healthy
  db:
    image: mariadb:11.8
    restart: unless-stopped
    environment:
      MARIADB_DATABASE: yourls
      MARIADB_USER: yourls
      MARIADB_PASSWORD: ${DB_PASSWORD}
      MARIADB_ROOT_PASSWORD: ${DB_ROOT_PASSWORD}
    volumes:
      - db:/var/lib/mysql
    healthcheck:
      test: ["CMD", "healthcheck.sh", "--connect", "--innodb_initialized"]
      interval: 5s
      timeout: 5s
      retries: 12
      start_period: 60s

volumes:
  db:
```

[compose.yaml](https://pethost.dev/templates/yourls/compose.yaml)[See it on GitHub](https://github.com/pethost-dev/templates/tree/main/yourls)

Pethost · Stephan Gomer · NIP 1133096755

[Templates](https://pethost.dev/templates/) [About](https://pethost.dev/about/) [Blog](https://pethost.dev/blog/) [Terms](https://pethost.dev/terms/) [Privacy](https://pethost.dev/privacy/) [Refunds](https://pethost.dev/refunds/) [API](https://pethost.dev/docs/api/) [CLI](https://pethost.dev/docs/cli/) [Plugin](https://github.com/pethost-dev/plugin) [support@pethost.dev](mailto:support@pethost.dev)
