How to Install Shlink on FreeBSD Latest
Introduction
Shlink is an open source URL shortener that allows you to manage your own short URLs. It also provides analytics to better understand your audience. In this tutorial, you will learn how to install Shlink on FreeBSD Latest.
Prerequisites
- A FreeBSD latest server.
- Root access to the server.
- Basic knowledge of the command line.
Step 1: Install Dependencies
Before you can install Shlink on FreeBSD Latest, you need to install the necessary dependencies. To do this, run the following command:
pkg update && pkg upgrade && pkg install -y php74 php74-xml php74-tokenizer php74-mbstring php74-intl php74-gd php74-curl php74-zip php74-fileinfo php74-ctype composer wget unzip nano mysql57-server php74-mysqli php74-pdo
Step 2: Download Shlink
After installation of dependencies, you need to download Shlink from the official website. To download the latest version of Shlink, run the following command:
wget https://github.com/shlinkio/shlink/releases/download/v3.10.1/shlink_3.10.1_phar.zip
After the download finishes, you should unzip the file by running the following command:
unzip shlink_3.10.1_phar.zip
Step 3: Move Shlink to the Web Directory
Next, move the Shlink directory to the web directory by running the following command:
mv shlink /usr/local/www/apache24/data/
Step 4: Prepare Shlink Configuration
Shlink requires some configurations before you can get it up and running. You will need to create a configuration file from the provided sample configuration file. To do this, run the following commands:
cd /usr/local/www/apache24/data/shlink
cp config/autoload/doctrine.global.php.dist config/autoload/doctrine.global.php
cp config/autoload/doctrine-orm.global.php.dist config/autoload/doctrine-orm.global.php
cp config/autoload/dependencies.global.php.dist config/autoload/dependencies.global.php
cp config/autoload/mezzio-swoole.global.php.dist config/autoload/mezzio-swoole.global.php
Step 5: Edit Shlink Configuration
Now that you have created the configuration files, you need to edit them to add your own details. Start by editing the following files:
nano /usr/local/www/apache24/data/shlink/config/autoload/doctrine.global.php
nano /usr/local/www/apache24/data/shlink/config/autoload/doctrine-orm.global.php
nano /usr/local/www/apache24/data/shlink/config/autoload/dependencies.global.php
In the doctrine.global.php file, add your database settings as follows:
'dbal' => [
// setup doctrine dbal configuration
'connection' => [
'url' => 'mysql://[username]:[password]@localhost:3306/[database]',
]
],
In the doctrine-orm.global.php file, add the following lines:
Entity::class => [
'app_entity' => [
'path' => '/usr/local/www/apache24/data/shlink/src/App/Entity',
'namespace' => 'App\Entity',
],
],
Finally, in the dependencies.global.php file, add the following lines:
// configure dependencies for App\Entity\ManagerInterface
App\Entity\ManagerInterface::class => DI\factory([Doctrine\ORM\EntityManager::class, 'getRepository'])->parameter('entityName', App\Entity\ShortUrl::class),
// configure dependencies for App\Action\ShortUrl\ResolveShortUrl
App\Action\ShortUrl\ResolveShortUrl::class => DI\create()->constructor(DI\get(App\Entity\ManagerInterface::class)),
Step 6: Initialize Shlink Database
With Shlink files in place, configurations are made successfully, and the database is now ready. You need to initialize the Shlink database by running the following command:
cd /usr/local/www/apache24/data/shlink
php74 bin/run init-db
Step 7: Start Shlink
Finally, it's time to start Shlink. Run the following command:
php74 bin/run serve -v
The '-v' flag is to display verbose messages from the server.
Conclusion
Congratulations, you have successfully installed Shlink URL shortener on FreeBSD latest. You can now start generating short URLs and track analytics.