Dernière modification le : Jul 21 2023 at 05:42 PM

Koel est un service de streaming audio personnel avec une interface web, il est écrit en Vue du côté client et en Laravel du côté serveur.

Préparation du serveur

On maj un coup

sudo apt update && sudo apt upgrade

Puis on install la base

sudo apt install vim ca-certificates curl unzip build-essential libpng-dev gnupg2 lsb-release openssl

Nodejs

Ici on utilise la version 16 qui est la dernière LTS Version au moment de l’écriture de ces lignes.

curl -sL https://deb.nodesource.com/setup_16.x | sudo -E bash -
sudo apt install -y nodejs

Yarn

curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt update && sudo apt install -y yarn

Php

J’utilise Postgresql vous pouvez utiliser Mysql/MariaDB aussi, dans ce cas installer le paquet php-mysql.

La version 6.x.x nécessite le passage à php8 et Nodejs v16 minimum

sudo apt install -y php-fpm php-mbstring php-bcmath php-xml php-pgsql php-curl php-zip php-xsl php-gd php-opcache

Postgresql

su - postgres
psql
CREATE USER koel WITH PASSWORD 'mot_de_passe';
CREATE DATABASE koel;
GRANT ALL PRIVILEGES ON DATABASE koel to koel;

Installer Composer

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === '906a84df04cea2aa72f40b5f787e49f22d4c2f19492ac310e8cba5b96ac8b64115ac402c8cd292b8a03482574915d1a8') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer
php -r "unlink('composer-setup.php');"

Puis on vérifie que tout fonctionne.

composer --version
> Composer version 2.1.12 2021-11-09 16:02:04

En cas de problème voir le site de Composer

Installer Koel

Et enfin on s’attaque à Koel, ici on installe la version avec les assets pré-compilé (parce que l’autre méthode ne fonctionne … pas/plus)

wget https://github.com/koel/koel/releases/download/v5.1.8/koel-v5.1.8.zip && unzip koel-v5.1.8.zip
sudo chown -R user:user /var/www/koel
cd koel/

On installe les dépendances

composer install

Et lance le script d’installation, qui vous demandera de renseigner la base de donnée utilisé et les infos de cette dernière.

php artisan koel:init --no-assets

À la fin celui-ci vous donnera l’email et le mot de passe pour vous connecter.

On repasse le dossier à www-data dans la foulée.

sudo chown -R www-data:www-data /var/www/koel

Il va falloir étoffer le .env créé après le koel:init --no-assets, il ne contient que les informations concernant la base de donnée pour le moment. vous trouverez d’autres options dans le .env.example, comme les options pour se connecter à certains services (LastFM, Spotify …)

Exemple de configuration.

APP_NAME=Koel

DB_CONNECTION=pgsql
DB_HOST=localhost
DB_PORT=5432
DB_DATABASE=user
DB_USERNAME=user
DB_PASSWORD=mot_de_passe_user

# By default, Koel ignores dot files and folders. This greatly improves performance if your media
# root have folders like .git or .cache. If by any chance your media files are under a dot folder,
# set the following setting to false.
IGNORE_DOT_FILES=true

APP_ENV=production
APP_DEBUG=true
APP_URL=http//votre_adresse.com

# The streaming method.
# Can be either 'php' (default), 'x-sendfile', or 'x-accel-redirect'
# See https://docs.koel.dev/#streaming-music for more information.
# Note: This setting doesn't have effect if the media needs transcoding (e.g. FLAC).
# ##################################################
# IMPORTANT: It's HIGHLY recommended to use 'x-sendfile' or 'x-accel-redirect' if
# you plan to use the Koel mobile apps.
# ##################################################
STREAMING_METHOD=php

# The bit rate of the output mp3 stream. Higher value results in better quality,
# but slower streaming and more bandwidth.
OUTPUT_BIT_RATE=320

# Whether to allow song downloading.
# Note that if you're downloading more than one song, Koel will zip them up
# using PHP's ZipArchive. So if the module isn't available in the current
# environment, such a download will (silently) fail.
ALLOW_DOWNLOAD=true

# If this is set to true, the query to get artist, album, and song information will be cached.
# This can give a boost to Koel's boot time, especially if your library is huge.
# However, the cache deserialization process can be memory sensitive, so if you encounter
# errors, try setting this to false.
CACHE_MEDIA=true

Nginx

Si vous ne comptez pas utiliser Koel autrement qu’en réseau local, vous pouvez passer cette étape.

sudo apt install nginx certbot python3-certbot-nginx

Puis copie le nginx.conf.example qui se trouve dans le dossier de koel dans /etc/nginx/conf.d/, puis on adapte les parties dont on a besoin.

sudo cp /var/www/html/koel/nginx/conf.example /etc/nginx/conf.d/
sudo mv /etc/nginx.conf.d/nginx/conf.example /etc/nginx/conf.d/koel.conf

Cela devrait ressembler a ça une fois arrangé.

server {
  listen          80;
  server_name     mon_super_domaine.tld; # Votre nom de domaine.
  root            /var/www/koel/public; # Mettre le chemin vers le dossier public de koel.
  index           index.php;

  gzip            on;
  gzip_types      text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript application/json;
  gzip_comp_level  9;

  location /media/ {
    internal;

    alias       $upstream_http_x_media_root;

    #access_log /var/log/nginx/koel.access.log;
    #error_log  /var/log/nginx/koel.error.log;
  }

  location / {
    try_files   $uri $uri/ /index.php?$args;
  }

  location ~ \.php$ {
    try_files $uri $uri/ /index.php?$args;

    fastcgi_param     PATH_INFO $fastcgi_path_info;
    fastcgi_param     PATH_TRANSLATED $document_root$fastcgi_path_info;
    fastcgi_param     SCRIPT_FILENAME $document_root$fastcgi_script_name;

    fastcgi_pass              unix:/var/run/php/php8.1-fpm.sock; # Votre version de php-fpm.
    fastcgi_index             index.php;
    fastcgi_split_path_info   ^(.+\.php)(/.+)$;
    fastcgi_intercept_errors  on;
    include                   fastcgi_params;
  }
}

Puis on vérifie que tout va bien et on relance.

nginx -t
systemctl restart nginx

HTTPS via Certbot

Si vous ne compter pas utiliser Koel autrement qu’en réseau local, vous pouvez passer cette étape.

sudo apt install certbot python3-certbot-nginx

Générons ensuite le tout.

sudo certbot --nginx -d votre_adresse.com
Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.
-------------------------------------------------------------------------------
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
-------------------------------------------------------------------------------
Select the appropriate number [1-2] then [enter] (press 'c' to cancel):

On sélectionne le 2 et zou, rendez-vous sur votre_adresse.com et voilà, reste plus qu’a vous connecter, changer le mail, le mdp et pseudo du compte admin.