English
Get started

← All templates · Productivity

Deploy YOURLS in one click

Your own URL shortener with click stats

A self-hosted alternative to Bitly and TinyURL.

What is YOURLS?

YOURLS is an open-source URL shortener that people run on their own domain instead of Bitly. Paste a long link, type a custom keyword or leave it blank for the next one in sequence, and you get a short URL that redirects to it. Every click is counted. A link's stats page charts its clicks over time, its top countries and its referrers, and adding a + to any short URL opens it, behind your login by default.

People self-host it to keep their links and click data in their own database, under a name they control. YOURLS is MIT-licensed and small on purpose: its makers leave out what most people would not use, and dozens of plugins add the rest. It suits anyone who shortens links often: bookmarklets shorten the page you are reading, and an API creates, expands and reports on links for your scripts.

Hosting YOURLS on Pethost

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

Questions about YOURLS

Is YOURLS free and open source?

Yes. YOURLS is free software under the MIT license, so you can run, change and share it at no cost, and its documentation is under CC BY 4.0.

Can YOURLS make random short URLs?

Yes. By default it hands out keywords in sequence: 1, 2, 3 and on. The Random ShortURLs plugin, which comes with YOURLS, gives random five-character keywords once you activate it under Manage Plugins.

Can YOURLS make QR codes?

Not by itself. The QRCode plugin in the YOURLS docs shows a link's code when you add .qr to the short URL, made by api.qrserver.com; QRCode Local, from the Awesome YOURLS list, draws it in the browser instead.

Can YOURLS have multiple users?

Yes, but they share one list of links: config.php can hold several logins, and each sees every link. The Auth Manager Plus plugin gives each user their own links and role-based permissions.

How do I change the YOURLS admin password?

With this template it is ADMIN_PASSWORD in the project's .env, read at every start: change it and deploy again. On a usual install it sits in $yourls_user_passwords in config.php, and YOURLS swaps it for a hash.

How much memory and disk does YOURLS need?

YOURLS is light: about 100 MB with MariaDB, and millions of logged clicks take a few gigabytes. On Pethost the Starter plan is enough for it, with room for other apps beside it.

YOURLS Docker Compose file

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

Containers: yourls (yourls:1.10.6-apache), db (mariadb:11.8).

Volumes, in the nightly backup: db.

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:

More in Productivity