Back to articles
Technology Insight

How to Self-Host Koel on a VPS: Build Your Personal Spotify Alternative Using MP3 Files

June 1, 2026

Introduction: Why Build Your Own Music Streaming Platform?

In the digital age, streaming services like Spotify, Apple Music, and YouTube Music have revolutionized how we consume audio content. However, these centralized platforms come with distinct disadvantages: recurring monthly subscription fees, unexpected licensing shifts that cause your favorite albums to vanish overnight, and the unavoidable privacy trade-offs of tracking your listening habits. For audiophiles, tech enthusiasts, and privacy advocates, there is a superior alternative: self-hosting.

By deploying Koel on a Virtual Private Server (VPS), you can liberate your personal music collection. Koel is an open-source, web-based audio streaming service written in Vue on the frontend and Laravel on the backend. Using a clean, modern interface that heavily mirrors Spotify, Koel allows you to stream your own collection of MP3, FLAC, or AAC files seamlessly across devices. This extensive technical guide will walk you through the complete architecture and deployment process to establish your own cloud-hosted music paradise.

---

The Prerequisites: What You Need Before Deployment

Before initiating the installation process, ensure that you have gathered the necessary infrastructure and components. Preparing these elements in advance guarantees a smooth, error-free deployment pipeline.

  • A Virtual Private Server (VPS): A baseline server with at least 1 vCPU, 1GB to 2GB of RAM, and sufficient SSD storage to house your music files. Providers like DigitalOcean, Linode, Vultr, or Hetzner are excellent choices.
  • Operating System: Ubuntu 22.04 LTS or Ubuntu 24.04 LTS is highly recommended for optimal package compatibility.
  • A Fully Qualified Domain Name (FQDN): A domain name (e.g., music.yourdomain.com) pointed directly to your VPS IP address via an A record.
  • SSH Client: Access to a terminal or SSH client (like PuTTY or OpenSSH) with root or sudo privileges.
---

Step 1: System Update and Core Dependency Installation

To support Koel's modern Laravel and Vue architecture, your system must run a modern stack consisting of PHP, Node.js, a relational database, and a reverse proxy. Connect to your VPS via SSH and execute the following commands to update the system and install core utilities.

Always ensure your package manager is updated before installing new software stacks to avoid dependency conflicts.

Run the update commands:

sudo apt update && sudo apt upgrade -y

Next, install the common software properties and auxiliary utilities:

sudo apt install -y curl git unzip zip software-properties-common

---

Step 2: Installing PHP 8.2 and Required Extensions

Koel requires PHP to execute its robust backend routing, database interactions, and file scanning routines. Install PHP 8.2 along with the specific extensions needed for media processing, database connectivity, and string manipulation.

First, add the Ondřej Surý PHP repository to ensure access to stable PHP versions:

sudo add-apt-repository ppa:ondrej/php -y
sudo apt update

Now, install PHP 8.2, the PHP Command Line Interface, FastCGI Process Manager (FPM), and the required operational extensions:

sudo apt install -y php8.2 php8.2-cli php8.2-fpm php8.2-mysql php8.2-xml php8.2-curl php8.2-mbstring php8.2-zip php8.2-gd php8.2-bcmath

Verify the successful installation of PHP by checking the active version:

php -v

---

Step 3: Database Configuration with MariaDB

Koel uses a database to index your music metadata, store user accounts, catalog playlists, and maintain playback configurations. We will utilize MariaDB for its speed and reliability.

Install the MariaDB server package:

sudo apt install -y mariadb-server

Secure the installation by running the integrated security script. Follow the prompts to set a strong root password, remove anonymous users, and disallow root logins remotely:

sudo mysql_secure_installation

Log into the MariaDB monitor to create a dedicated database and user account for Koel:

sudo mysql -u root -p

Execute the following SQL queries within the prompt, replacing 'YourStrongPassword' with a unique, secure string:CREATE DATABASE koel CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'koel_user'@'localhost' IDENTIFIED BY 'YourStrongPassword';
GRANT ALL PRIVILEGES ON koel.* TO 'koel_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;

---

Step 4: Installing Node.js, Yarn, and Composer

Koel relies on Composer to manage its backend PHP dependencies, and Yarn along with Node.js to compile its frontend structural components. Install these developer tools efficiently using the official node source scripts.

Install Node.js (Version 18 or newer is recommended for compatibility):

curl -fsSL [https://deb.nodesource.com/setup_18.x](https://deb.nodesource.com/setup_18.x) | sudo -E bash -
sudo apt install -y nodejs

Enable Corepack to globally install Yarn, which is heavily utilized by Koel’s frontend compilation steps:

sudo corepack enable
sudo corepack prepare yarn@stable --activate

Download and install Composer globally onto your system path:

curl -sS [https://getcomposer.org/installer](https://getcomposer.org/installer) | php
sudo mv composer.phar /usr/local/bin/composer

---

Step 5: Cloning and Configuring the Koel Application

With the baseline environment fully prepared, navigate to your web deployment directory, pull the official Koel source code repository from GitHub, and execute configuration protocols.

Navigate to the default web directory and clone the repository:

cd /var/www
sudo git clone [https://github.com/koel/koel.git](https://github.com/koel/koel.git)
cd koel

Install the application's backend PHP packages via Composer:

sudo composer install

Create your custom environment configuration file by duplicating the provided distribution template:

sudo cp .env.example .env

Open the configuration file using a text editor such as Nano to link your database and define your server settings:

sudo nano .env

Modify the variables to precisely match your server setup, paying close attention to the base URL and database configurations:

APP_URL=[https://music.yourdomain.com](https://music.yourdomain.com)

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=koel
DB_USERNAME=koel_user
DB_PASSWORD=YourStrongPassword

Save the changes and exit the text editor. Initialize the primary application key, structure the database tables via Laravel migrations, and create your administrative account by running the integrated installation command:

sudo php artisan koel:init

Follow the terminal prompts carefully to set up your primary administrator email address and secure password.

---

Step 6: Frontend Asset Compilation and Permissions Management

To interact with Koel's visual player layout, you must compile the modern Vue components. Run the asset building scripts directly within the application directory:

sudo yarn install
sudo yarn build

For Koel to run reliably and accept future updates seamlessly, assign directory ownership to the standard Linux web user profile (www-data):

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

---

Step 7: Configuring Nginx Reverse Proxy and Let's Encrypt SSL

To safely expose Koel to the internet over a secure HTTPS protocol, configure Nginx as a reverse proxy coupled with an SSL certificate provided by Let's Encrypt.

Install Nginx:

sudo apt install -y nginx

Create a dedicated configuration block for Koel:

sudo nano /etc/nginx/sites-available/koel

Insert the following server configuration block, ensuring you modify the server_name parameter to mirror your real domain name:server {
listen 80;
server_name music.yourdomain.com;
root /var/www/koel/public;

index index.php;

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

location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php8.2-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}

location ~ /\.(?!well-known).* {
deny all;
}
}

Enable the site configuration by establishing a symbolic link to the active directory, and restart the web server daemon:

sudo ln -s /etc/nginx/sites-available/koel /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl restart nginx

To encrypt your audio streams, install Certbot and configure your free SSL certificate:

sudo apt install -y certbot python3-certbot-nginx
sudo certbot --nginx -d music.yourdomain.com

Follow the interactive commands to complete the certificate installation and automatically configure secure traffic redirection from HTTP to HTTPS.

---

Step 8: Uploading and Media Synchronization Protocols

With Koel successfully hosted and secured, you must designate a directory on your VPS to store your music files (e.g., /var/www/koel/music). Ensure this folder has proper www-data read and write permissions.

Upload your audio tracks using secure protocols like SFTP or SCP. Once your files are uploaded to the folder, log in to your Koel web interface via your web browser using your administrator credentials, navigate to the **Settings** panel, and set your media path to point directly to that folder.

Alternatively, trigger a rapid structural server-side media scan manually via the command line to populate your library instantly:

sudo php artisan koel:sync

The artisan sync command meticulously crawls your directory structure, extracts metadata ID3 tags, and organizes your media content by artist, album, genre, and duration on your active dashboard.

---

Conclusion: Ultimate Audio Independence

Congratulations! You have effectively self-hosted Koel on a custom Virtual Private Server, creating a completely independent, reliable, subscription-free music streaming service. By executing this deployment, you have protected your data privacy, unlocked fine-grained audio customization controls, and ensured absolute control over your digital library. Sit back, invite your friends or family members to join your newly created server, and stream your high-fidelity personal tracks anytime, anywhere.

How to Self-Host Koel on a VPS: Build Your Personal Spotify Alternative Using MP3 Files | DPTCloud