Shlink is a self-hosted URL shortening service built with PHP, Mezzio, and Doctrine that allows users to create branded short links using their own domains. It’s designed for developers, marketers, and organizations seeking full control over their link data without relying on third-party services like Bitly. Shlink solves the problem of losing analytics, branding, and ownership when using external URL shorteners.
The application supports deployment via Docker or direct PHP installation, with built-in REST API, command-line interface, and a progressive web app frontend. It integrates with Redis, RabbitMQ, and Mercure for real-time updates, and supports MySQL, PostgreSQL, MariaDB, and SQLite for data persistence.
What You Get
- URL shortening - Generates short codes for long URLs with optional custom slugs and multi-segment paths.
- Visit stats - Tracks detailed analytics including geolocation, browser, device type, referrer, and timestamp for every click.
- Custom slugs - Allows users to define human-readable, memorable short URLs like yourbrand.com/offer2024.
- Multi-domain support - Host multiple short domains (e.g., short.co, go.mycompany.com) on a single Shlink instance with independent settings.
- Dynamic redirects - Conditionally redirect users based on geolocation, device type, language, or time of day.
- Tags - Organize and filter short URLs with custom tags for campaign tracking and analytics segmentation.
- API-first architecture - Full REST API with documented endpoints, OAuth2-style API keys, and role-based access control per domain or URL.
- Real-time updates - Subscribe to URL visit events via Mercure or RabbitMQ for live dashboards and automation.
- GDPR compliant - Anonymizes IP addresses by default to meet data privacy regulations without losing useful analytics.
- Third-party imports - Import existing short URLs from Bitly, YOURLS, and other URL shortening services via CSV or API.
- Bot detection - Filters out traffic from known bots and crawlers to ensure accurate visit statistics.
- Multiple database engines - Supports MySQL, MariaDB, PostgreSQL, Microsoft SQL Server, and SQLite with corresponding PDO drivers.
Common Use Cases
- Running a marketing campaign - A digital marketer uses Shlink to create branded short links with custom slugs and track click-through rates across email, social media, and ads.
- Managing internal tools - A DevOps team deploys Shlink on-premises to shorten links to internal dashboards, CI/CD pipelines, and documentation with their company domain.
- Building a link management platform - A SaaS startup uses Shlink’s API to offer branded URL shortening as a feature within their analytics dashboard.
- Complying with data privacy laws - A European organization self-hosts Shlink to retain full control over visitor data and ensure IP anonymization for GDPR compliance.
- Integrating with automation workflows - A developer uses Shlink’s REST API and Mercure to trigger notifications or update CRM records when a short link is clicked.
- Replacing Bitly for enterprise use - A corporate IT department migrates from Bitly to Shlink to eliminate vendor lock-in and gain full ownership of link analytics.
Under The Hood
Architecture
- Modular monorepo structure with distinct namespaces enforcing clear domain boundaries between core logic, REST API, and CLI interfaces
- Dependency injection via Laminas ServiceManager enables flexible service composition, with ConfigProvider classes centralizing service definitions
- Shared Core domain layer powers both CLI and REST endpoints, ensuring consistency while allowing interface-specific entry points
- Event-driven design decouples domain actions from side effects like analytics and notifications through a dedicated event dispatcher
- Infrastructure-agnostic persistence via Doctrine ORM with multi-database support and runtime flexibility across PHP servers
Tech Stack
- PHP 8.5+ backend built on Mezzio with Laminas components for routing, DI, and input handling
- Doctrine ORM and DBAL provide robust data persistence with full migration support across multiple SQL databases
- High-performance deployment options include RoadRunner and FrankenPHP for worker pooling and embedded server integration
- Docker-based multi-stage builds with orchestration for Redis, RabbitMQ, Mercure, and Matomo enable production-ready deployments
- Comprehensive testing stack with PHPUnit and PHPStan, enhanced with Symfony/Doctrine extensions for deep static analysis
Code Quality
- Strong type safety and value objects reduce runtime errors and improve code clarity across the domain model
- Well-defined layers and constructor-based dependency injection promote testability and maintainability
- Domain-specific exceptions provide meaningful context and are consistently mapped to appropriate HTTP responses
- Extensive test coverage with sophisticated utilities for mocking and data-driven testing ensures robust behavior
- CLI components feature adaptive logging and verbosity controls that preserve core functionality across environments
What Makes It Unique
- Deterministic, dependency-free short URL generation with built-in collision resistance and scalability
- Server-level URL redirection with embedded analytics that eliminates client-side scripts and per-hit database queries
- Extensible plugin system for geolocation and UTM tracking that integrates without modifying core routing
- Self-hosted real-time analytics dashboard with in-memory caching and lazy-loaded visualizations
- Zero-configuration deployment via Docker and CLI tools with automatic reverse proxy and TLS setup
- First-class API-driven URL lifecycle management with built-in rate limiting and access control hooks