The definitive self-hosted URL shortener
Go to file
2018-09-09 18:20:12 +02:00
bin Removed plugin suffix on config ustomizers 2017-12-31 17:18:54 +01:00
config Added version placeholder in place of hardcoded version in config 2018-07-26 18:42:53 +02:00
data Updated changelog with version 1.10.1 2018-08-01 20:58:48 +02:00
docs/swagger Updated API docs including new response structure 2018-08-13 16:17:43 +02:00
module Added v1.11.0 to changelog 2018-08-13 16:29:40 +02:00
public Updated to expressive 3 2018-03-26 18:49:28 +02:00
.env.dist Removed rest auth env vars 2016-08-07 20:47:43 +02:00
.gitattributes Added phpstan config file to export-ignore list 2017-12-30 21:39:18 +01:00
.gitignore Udated minimum PHP version and docker stuff 2017-10-12 09:24:47 +02:00
.phpstorm.meta.php Moved command and app creation logic to a factory for install scripts 2017-07-05 18:12:03 +02:00
.scrutinizer.yml Added CI config files 2016-04-17 19:34:16 +02:00
.travis.yml Dropped support for PHP 7.0 2018-03-26 18:16:59 +02:00
build.sh Simplified how built shlink version is found out 2018-07-26 20:35:02 +02:00
CHANGELOG.md Added v1.11.0 to changelog 2018-08-13 16:29:40 +02:00
composer.json Added shortUrl field to serialized ShortUrl objects, both from CLI and REST 2018-08-10 23:14:45 +02:00
docker-compose.override.yml.dist Udated minimum PHP version and docker stuff 2017-10-12 09:24:47 +02:00
docker-compose.yml Updated PathVersionMiddleware so that it is only applied to rest routes 2017-01-21 20:12:12 +01:00
func_tests_bootstrap.php Ensured same testing database is used to generate with entities and to run functional tests 2017-10-23 12:19:28 +02:00
indocker Created docker-related files 2017-01-19 22:56:45 +01:00
infection.json Updated to phpstan 0.10 and infection 0.9 2018-07-04 12:08:27 +02:00
LICENSE Updated license year 2017-01-22 10:59:35 +01:00
migrations.yml Added doctrine migrations and remove platform specific code from entities 2016-08-19 14:51:34 +02:00
phpcs.xml Improved coding styles 2017-10-12 10:13:20 +02:00
phpstan.neon Fixed coding styles 2018-07-31 19:53:59 +02:00
phpunit-func.xml Implemented EditShortCodeAction 2018-01-07 20:45:05 +01:00
phpunit.xml.dist Implemented EditShortCodeAction 2018-01-07 20:45:05 +01:00
README.md Improved documentation in README file 2018-09-09 18:20:12 +02:00

Shlink

Build Status Code Coverage Scrutinizer Code Quality Latest Stable Version License Paypal donate

A PHP-based self-hosted URL shortener that can be used to serve shortened URLs under your own custom domain.

Installation

First make sure the host where you are going to run shlink fulfills these requirements:

  • PHP 7.1 or greater with JSON, APCu, intl, curl, PDO and gd extensions enabled.
  • MySQL, PostgreSQL or SQLite.
  • The web server of your choice with PHP integration (Apache or Nginx recommended).

Then, you will need a built version of the project. There are a few ways to get it.

  • Using a dist file

    The easiest way to install shlink is by using one of the pre-bundled distributable packages.

    Just go to the latest version and download the shlink_X.X.X_dist.zip file you will find there.

    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.
    • Use composer to install the production project dependencies by running php composer.phar install --no-dev --optimize-autoloader --no-progress --no-interaction.

Despite how you built the project, you are going to need to install it now, by following these steps:

  • If you are going to use MySQL or PostgreSQL, 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.

  • Setup the application by running the bin/install script. It will guide you through the installation process.

  • Configure the web server of your choice to serve shlink using your short domain.

    For example, assuming your domain is doma.in and shlink is in the /path/to/shlink folder, this would be the basic configuration for Nginx and Apache.

    Nginx:

    server {
        server_name doma.in;
        listen 80;
        root /path/to/shlink/public;
        index index.php;
        charset utf-8;
    
        location / {
            try_files $uri $uri/ /index.php$is_args$args;
        }
    
        location ~ \.php$ {
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
            fastcgi_index index.php;
            include fastcgi.conf;
        }
    
        location ~ /\.ht {
            deny all;
        }
    }
    

    Apache:

    <VirtualHost *:80>
        ServerName doma.in
        DocumentRoot "/path/to/shlink/public"
    
        <Directory "/path/to/shlink/public">
            Options FollowSymLinks Includes ExecCGI
            AllowOverride all
            Order allow,deny
            Allow from all
        </Directory>
    </VirtualHost>
    
  • 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.

  • Finally access to https://app.shlink.io and configure your server to start creating short URLs.

Bonus

There are a couple of time-consuming tasks that shlink expects you to do manually, or at least it is recommended, since it will improve runtime performance.

Those tasks can be performed using shlink's CLI, so it should be easy to schedule them to be run in the background (for example, using cron jobs):

  • Resolve IP address locations: /path/to/shlink/bin/cli visit:process

    If you don't run this command regularly, the stats will say all visits come from unknown locations.

  • Generate website previews: /path/to/shlink/bin/cli shortcode:process-previews

    Running this will improve the performance of the doma.in/abc123/preview URLs, which return a preview of the site.

Update to new version

When a new Shlink version is available, you don't need to repeat the whole process yourself.

Instead, get the latest version as explained in previous step, and then, run the script bin/update.

The script will ask you for the location from previous shlink version, and use it in order to import the configuration.

It will then update the database and generate some assets.

Right now, it does not import cached info (like website previews), but it will. By now you will need to regenerate them again.

Important! It is recommended that you don't skip any version when using this process. The update gets better on every version, but older versions might make assumptions.

Using a docker image

Currently there's no official docker image, but there's a work in progress alpha version you can find here.

The idea will be that you can just generate a container using the image and provide predefined config files via volumes or CLI arguments, so that you get shlink up and running.

Currently the image does not expose an entry point which let's you interact with shlink's CLI interface, nor allows configuration to be passed.

Once shlink is installed, there are two main ways to interact with it, in order to create shortened URLs:

  • The command line. Try running bin/cli and see all the available commands.

    All of those commands 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 symlinking 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 here.

    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 you can host it yourself too.

Both the API and CLI allow you to do the same operations, except for API key management, which can be done from the command line only.