A PHP-based self-hosted URL shortener that can be used to serve shortened URLs under your own domain.
This document contains the very basics to get started with Shlink. If you want to learn everything you can do with it, visit the full searchable documentation.
You can learn how to use the official docker image by reading the docs.
The idea is that you can just generate a container using the image and provide the custom config via env vars.
First, make sure the host where you are going to run shlink fulfills these requirements:
- PHP 8.2 or 8.3
- The next PHP extensions: json, curl, pdo, intl, gd and gmp/bcmath.
- apcu extension is recommended if you don't plan to use RoadRunner.
- xml extension is required if you want to generate QR codes in svg format.
- sockets and bcmath extensions are required if you want to integrate with a RabbitMQ instance.
- MySQL, MariaDB, PostgreSQL, MicrosoftSQL or SQLite.
- You will also need the corresponding pdo variation for the database you are planning to use:
pdo_mysql
,pdo_pgsql
,pdo_sqlsrv
orpdo_sqlite
.
- You will also need the corresponding pdo variation for the database you are planning to use:
In order to run Shlink, you will need a built version of the project. There are two ways to get it.
-
Using a dist file
The easiest way to install shlink is by using one of the pre-bundled distributable packages.
Go to the latest version and download the
shlink*_dist.zip
file that suits your needs. You will find one for every supported PHP version.Finally, decompress the file in the location of your choice.
-
Building from sources
If for any reason you want to build the project yourself, follow these steps:
- Clone the project with git (
git clone https://github.com/shlinkio/shlink.git
), or download it by clicking the Clone or download green button. - Download the Composer PHP package manager inside the project folder.
- Run
./build.sh 3.0.0
, replacing the version with the version number you are going to build (the version number is used as part of the generated dist file name, and to set the value returned when runningshlink -V
from the command line).
After that, you will have a dist file inside the
build
directory, that you need to decompress in the location of your choice.Note
This is the process used when releasing new Shlink versions. After tagging the new version with git, the GitHub release is automatically created by a GitHub workflow, attaching the generated dist file to it.
- Clone the project with git (
Despite how you built the project, you now need to configure it, by following these steps:
- If you are going to use MySQL, MariaDB, PostgreSQL or Microsoft SQL Server, create an empty database with the name of your choice.
- Recursively grant write permissions to the
data
directory. Shlink uses it to cache some information. - Set up the application by running the
vendor/bin/shlink-installer install
script. It is a command line tool that will guide you through the installation process. Take into account that this tool has to be run directly on the server where you plan to host Shlink. Do not run it before uploading/moving it there. - Generate your first API key by running
bin/cli api-key:generate
. You will need the key in order to interact with Shlink's API.
Once shlink is installed, there are two main ways to interact with it:
-
The command line: Try running
bin/cli
to see all the available commands.All of them can be run with the
--help
/-h
flag in order to see how to use them and all the available options.It is probably a good idea to symlink the CLI entry point (
bin/cli
) to somewhere in your path, so that you can run shlink from any directory. -
The REST API: The complete docs on how to use the API can be found here, and a sandbox which also documents every endpoint can be found in the API Spec portal.
However, you probably don't want to consume the raw API yourself. That's why a nice web client is provided that can be directly used from https://app.shlink.io, or hosted by yourself.
Both the API and CLI allow you to do mostly the same operations, except for API key management, which can be done from the command line interface only.
If you are trying to find out how to run the project in development mode or how to provide contributions, read the CONTRIBUTING doc.
This product includes GeoLite2 data created by MaxMind, available from https://www.maxmind.com