Installation

Shlink is a web application built with PHP. It shouldn't be hard to install, but you have to follow these steps.

Requirements

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

Installation steps

  • Download the latest distributable file and decompress it at the location of your choice
  • Create an empty database (not necessary if you are going to use SQLite)
  • Setup the application by running the bin/install script. It will guide you through the installation process.
  • Recursively grant write permissions to the data directory.
  • Optionally, you can create a symlink to the bin/cli script in a folder which is in your path.
    For example /usr/local/bin for linux systems. This will allow you to easily run shlink from anywhere in the command line.

Virtual hosts

These are samples for the most used web servers. Use them to get shlink up and running.

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.0-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>
                    

Resource-consuming tasks

Resolving the IP of a visitor in order to get its location involves performing a request to an external service, which gets time. For this reason, this task is not done in real time.

You can manually run the command visit:process which will process all the IPs from visits.

Alternatively, you could create an scheduled task which automatically runs that command so that the information is updated periodically.

This is an example cron job that could be created under a Unix system. It will run the command every hour, processing all pending IP addresses:

0 * * * * /path/to/shlink/bin/cli visit:process

Something similar happens with page previews. Shlink is capable of generating the preview of a page behind a short code by appending the /preview path to a short URL. For example, https://doma.in/abc123/preview.

If you access that URL, the image will be generated and cached, but the first time, the request will take a little bit more time.

In order to prevent this, you can use the command shortcode:process-previews, which will generate all missing previews so that any later web request is faster

This command can be configured for a cron job too:

30 * * * * /path/to/shlink/bin/cli shortcode:process-previews