Introduction

URL shorteners are essential tools for managing long links, tracking clicks, and maintaining branded short domains. While services like Bitly dominate the commercial space, privacy-conscious teams and self-hosting enthusiasts have excellent open-source alternatives. This guide compares three of the most popular self-hosted URL shorteners: Shlink, YOURLS, and Polr — covering features, deployment, analytics, and API capabilities.

Overview Comparison

FeatureShlinkYOURLSPolr
LanguagePHP (Symfony-based)PHPPHP (Laravel)
DatabaseMySQL, PostgreSQL, SQLite, MariaDBMySQL, SQLiteMySQL, MariaDB, SQLite
Docker SupportOfficial imageCommunity/LinuxServerDocker Hub image
APIFull REST APIPlugin-based APIREST API
Click AnalyticsBuilt-in, detailedPlugin-basedBuilt-in
QR Code GenerationBuilt-inVia pluginNo (plugin needed)
Custom DomainsMulti-domain supportSingle domainSingle domain
OAuth/AuthAPI key authenticationPassword + pluginOAuth2, API key
Web UIOptional (shlink-web-ui)Built-in adminBuilt-in admin
Tags/OrganizationYesVia pluginYes
Preview PagesYesVia pluginYes
Bulk ImportCLI + APICSV import pluginCSV import
LicenseMITGPL-2.0MIT
GitHub Stars~4,960~12,000~5,100

Shlink is a feature-rich, open-source URL shortener written in PHP. It supports multiple databases, offers a comprehensive REST API, and includes built-in analytics and QR code generation. Its CLI tool (shlink-cli) makes it easy to manage links from the terminal.

Key Features

  • Multi-database support — MySQL, PostgreSQL, SQLite, MariaDB
  • Built-in analytics — Visit tracking with geographic data, referrer tracking, and device detection
  • QR code generation — Automatic QR codes for every short URL
  • Tag-based organization — Group and filter links by tags
  • REST API — Full API for programmatic management
  • CLI tool — Terminal-based link management
  • Custom short codes — Define your own short URL slugs
  • Domain management — Support multiple domains for short URLs

Docker Compose Deployment

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
version: "3.8"

services:
  shlink:
    image: shlinkio/shlink:stable
    restart: unless-stopped
    ports:
      - "8080:8080"
    environment:
      - DEFAULT_DOMAIN=short.example.com
      - IS_HTTPS_ENABLED=false
      - INITIAL_API_KEY=your-secret-api-key
      - DB_DRIVER=sqlite
      - DB_NAME=data/shlink.db
    volumes:
      - shlink_data:/opt/shlink/data

  shlink-web:
    image: shlinkio/shlink-web-ui:latest
    restart: unless-stopped
    ports:
      - "3000:8080"
    environment:
      - SHLINK_SERVER_URL=http://shlink:8080
    depends_on:
      - shlink

volumes:
  shlink_data:

Installation Steps

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
# Pull and start with Docker Compose
docker-compose up -d

# Or use the Shlink CLI for local installation
composer create-project shlinkio/shlink
cd shlink
bin/cli shlink:install

# Create your first short URL via API
curl -X POST http://localhost:8080/rest/v3/short-urls   -H "X-Api-Key: your-secret-api-key"   -H "Content-Type: application/json"   -d '{"longUrl": "https://example.com/very/long/url"}'

YOURLS: The De Facto Standard

YOURLS (Your Own URL Shortener) is the oldest and most widely adopted open-source URL shortener. Written in PHP, it offers a built-in admin interface, plugin architecture, and extensive community support. With over 12,000 GitHub stars, it is the most starred self-hosted URL shortener.

Key Features

  • Built-in admin interface — Manage links, view stats, and configure settings from a web UI
  • Plugin ecosystem — 100+ community plugins for extending functionality
  • Bookmarklet — Shorten URLs directly from your browser toolbar
  • Private or public — Control who can create short links
  • Sequential or custom keywords — Auto-generated or user-defined short URLs
  • JSONP API — Programmatic access with JSONP support
  • Geolocation tracking — Track visitor locations
  • Multiple user accounts — Role-based access control

Docker Compose Deployment

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
version: "3.8"

services:
  yourls:
    image: yourls:apache
    restart: unless-stopped
    ports:
      - "8080:80"
    environment:
      - YOURLS_SITE=http://short.example.com
      - YOURLS_USER=admin
      - YOURLS_PASSWORD=your-admin-password
      - YOURLS_DB_HOST=db
      - YOURLS_DB_USER=yourls
      - YOURLS_DB_PASS=yourls-secret
      - YOURLS_DB_NAME=yourls
    volumes:
      - yourls_data:/var/www/html
    depends_on:
      - db

  db:
    image: mariadb:10.11
    restart: unless-stopped
    environment:
      - MYSQL_ROOT_PASSWORD=root-secret
      - MYSQL_DATABASE=yourls
      - MYSQL_USER=yourls
      - MYSQL_PASSWORD=yourls-secret
    volumes:
      - db_data:/var/lib/mysql

volumes:
  yourls_data:
  db_data:

Configuration

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
// config.php - essential settings
define( 'YOURLS_DB_USER', 'yourls' );
define( 'YOURLS_DB_PASS', 'yourls-secret' );
define( 'YOURLS_DB_NAME', 'yourls' );
define( 'YOURLS_SITE', 'https://short.example.com' );
define( 'YOURLS_HOURS_OFFSET', 0 );
define( 'YOURLS_LANG', '' );
define( 'YOURLS_UNIQUE_URLS', true );
define( 'YOURLS_PRIVATE', true );

// User credentials
$yourls_user_passwords = [
    'admin' => 'password_hash_here',
];

Polr: The Lightweight Alternative

Polr is a modern, lightweight URL shortener built with PHP and Laravel. It features a clean admin interface, OAuth2 authentication, and a simple setup process. While it has fewer features than Shlink or YOURLS out of the box, its Laravel foundation makes it highly extensible.

Key Features

  • Laravel-based — Built on a modern PHP framework, easy to customize
  • OAuth2 authentication — Secure API access with OAuth2
  • Built-in analytics — Click tracking with geographic and referrer data
  • Admin dashboard — Clean web interface for link management
  • API support — RESTful API for programmatic access
  • Custom slugs — User-defined short URL paths
  • Lightweight — Minimal resource requirements

Docker Compose Deployment

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
version: "3.8"

services:
  polr:
    image: cydrobolt/polr:latest
    restart: unless-stopped
    ports:
      - "8080:80"
    environment:
      - APP_NAME=Polr
      - APP_ENV=production
      - DB_CONNECTION=mysql
      - DB_HOST=db
      - DB_PORT=3306
      - DB_DATABASE=polr
      - DB_USERNAME=polr
      - DB_PASSWORD=polr-secret
    depends_on:
      - db

  db:
    image: mysql:8.0
    restart: unless-stopped
    environment:
      - MYSQL_ROOT_PASSWORD=root-secret
      - MYSQL_DATABASE=polr
      - MYSQL_USER=polr
      - MYSQL_PASSWORD=polr-secret
    volumes:
      - polr_db:/var/lib/mysql

volumes:
  polr_db:

Nginx Reverse Proxy Configuration

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
server {
    listen 80;
    server_name short.example.com;

    location / {
        proxy_pass http://localhost:8080;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}

Why Self-Host Your URL Shortener?

Running your own URL shortener provides significant advantages over commercial services. You maintain complete ownership of your link data, including click analytics, geographic distributions, and referrer information. There is no risk of the service shutting down and breaking all your existing short links — a common problem with free URL shortener services.

Custom domain support lets you brand short URLs with your own domain, building trust and recognition. Self-hosted solutions also eliminate rate limits and usage caps imposed by commercial services, allowing unlimited link creation for teams and organizations.

For teams managing marketing campaigns, self-hosted URL shorteners provide detailed analytics without sending data to third-party platforms. If you also need to manage bookmarks and saved links, check our bookmark manager comparison. For monitoring broken links across your infrastructure, our link checker guide covers the best tools available.

When combined with self-hosted analytics platforms, URL shorteners create a powerful privacy-first tracking stack — see our privacy analytics guide for complementary tools.

FAQ

What is the best self-hosted URL shortener?

Shlink is generally considered the best all-around self-hosted URL shortener due to its rich feature set, multi-database support, built-in analytics, QR code generation, and active development. YOURLS is the most popular option with the largest plugin ecosystem, while Polr is the most lightweight and easiest to set up.

Can I use a custom domain with self-hosted URL shorteners?

Yes, all three tools support custom domains. Shlink has the most advanced multi-domain support, allowing you to manage short URLs across multiple domains from a single instance. YOURLS and Polr support single custom domains with proper DNS and web server configuration.

Do self-hosted URL shorteners provide click analytics?

Shlink and Polr include built-in click analytics with geographic data, referrer tracking, and device detection. YOURLS requires plugins for analytics, but the community offers several robust options including GeoIP tracking and real-time dashboards.

Can I import bulk URLs into a self-hosted shortener?

Yes. Shlink supports bulk import via its CLI and REST API. YOURLS has CSV import plugins. Polr supports CSV import through its admin interface. All three tools allow programmatic URL creation through their APIs.

How do I back up my self-hosted URL shortener?

For Docker-based deployments, back up the database volume and any persistent data directories. Shlink uses SQLite by default (back up the data directory), while YOURLS and Polr typically use MySQL/MariaDB (use mysqldump for database backups). Regular automated backups via cron are recommended.

Are self-hosted URL shorteners secure?

All three tools offer authentication mechanisms. Shlink uses API key authentication, YOURLS has password-protected admin access with plugin-based OAuth, and Polr supports OAuth2 and API key authentication. Always use HTTPS in production and keep your tools updated.

Which URL shortener has the best API?

Shlink has the most comprehensive REST API with full CRUD operations for links, tags, domains, and analytics. Polr offers a RESTful API with OAuth2 authentication. YOURLS provides a JSONP API that can be extended with plugins for additional endpoints.