Atlantic.Net Blog

Setup Personal Audio Streaming Server with Koel on Ubuntu 20.04

Hitesh Jethva
by Atlantic.Net (273 posts) under VPS Hosting
0 Comments

Koel is a simple, free, open-source, web-based personal audio streaming server written in PHP and JavaScript. It uses Laravel on the server-side and Vue on the client-side. Koel allows you to stream your music and access it from anywhere through the Internet. It supports many media formats, including AAC, OGG, WMA, FLAC and APE, and it can stream music over HTTP / HTTPS.

In this tutorial, we will explain how to install Koel Audio Streaming server on Ubuntu 20.04.

Prerequisites

  • A fresh Ubuntu 20.04 VPS on the Atlantic.Net Cloud Platform
  • A root password configured on your server

Step 1 – Create Atlantic.Net Cloud Server

First, log in to your Atlantic.Net Cloud Server. Create a new server, choosing Ubuntu 20.04 as the operating system with at least 4GB RAM. Connect to your Cloud Server via SSH and log in using the credentials highlighted at the top of the page.

Once you are logged into your Ubuntu 20.04 server, run the following command to update your base system with the latest available packages.

apt-get update -y

Step 2 – Install Required Dependencies

First, you will need to install some dependencies required for Koel. You can install all of them with the following command:

apt-get install git unzip curl build-essential libpng-dev gcc make ffmpeg -y

Once all the dependencies are installed, you can proceed to the next step.

Step 3 – Install LEMP Server

Next, you will need to install Nginx, MariaDB, PHP, and other PHP extensions in your system. You can install all of them with the following command:

apt-get install nginx mariadb-server php php-cli php-fpm php-json php-common php-mysql php-zip 
php-gd php-mbstring php-curl php-xml php-pear php-bcmath php-tokenizer openssl php-json -y

Note: If you get an error when Apache2 automatically starts – see this procedure.

After installing the above packages, Apache package will be installed automatically with PHP. Here, we will use Nginx web server so remove the Apache package with the following command:

systemctl stop apache2
apt-get purge apache2 -y

Next, edit the php.ini file and tweak some desired settings:

nano /etc/php/7.4/fpm/php.ini

Change the following lines:

memory_limit = 512M
date.timezone = Asia/Kolkata

Save and close the file when you are finished.

Step 4 – Install Composer

Composer is a dependency manager used for managing PHP dependencies. You can install it with the following command:

curl -sS https://getcomposer.org/installer -o composer-setup.php
php composer-setup.php --install-dir=/usr/local/bin --filename=composer

You should get the following output:

All settings correct for using Composer
Downloading...

Composer (version 1.10.10) successfully installed to: /usr/local/bin/composer
Use it: php /usr/local/bin/composer

Next, verify the installed version of Composer using the following command:

composer -V

You should get the following output:

Composer version 1.10.10 2020-08-03 11:35:19

Step 5 – Create a Database for Koel

Next, you will need to create a database and user for Koel.

First, log in to MariaDB with the following command:

mysql

Once logged in, create a database and user with the following command:

CREATE DATABASE koeldb;
CREATE USER 'koeluser'@'localhost' IDENTIFIED BY 'password';

Next, grant all the privileges to the Koel database with the following command:

GRANT ALL PRIVILEGES ON koeldb.* TO 'koeluser'@'localhost';

Next, flush the privileges and exit from the MariaDB shell with the following command:

FLUSH PRIVILEGES;
EXIT;

Step 6 – Install Node.js

You will also need to install the Node.js package in your server. By default, Node.js is not available in the Ubuntu 20.04 default repository, so add the Node.js repository with the following command:

curl -sL https://deb.nodesource.com/setup_12.x | bash -

Next, install the Node.js server with the following command:

apt-get install nodejs -y

After installing Node.js, add the Yarn GPG key and repository with the following command:

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

Next, update the repository and install the Yarn package with the following command:

apt-get update -y
apt install --no-install-recommends yarn

Step 7 – Install Koel

First, change the directory to the Nginx root directory and install Laravel dependencies using the following command:

cd /var/www/html
composer global require laravel/installer

Next, download the latest version of Koel with the following command:

git clone https://github.com/koel/koel.git --recursive

Once downloaded, change the directory to Koel and install Node dependencies with the following command:

cd koel
npm install
npm audit fix
npm audit fix --force

Finally, install PHP dependencies using the following command:

composer install

Next, edit the .env file and define your database and other settings:

nano .env

Change the following lines:

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=koeldb
DB_USERNAME=koeluser
DB_PASSWORD=password

ADMIN_NAME="admin"
[email protected]
ADMIN_PASSWORD=adminpassword

MEMORY_LIMIT=512
FFMPEG_PATH=/usr/bin/ffmpeg

Save and close the file, then initialize the database with the following command:

php artisan koel:init --no-interaction

You should get the following output:

Done in 156.20s.

🎆 Success! Koel can now be run from localhost with `php artisan serve`.
Again, visit 📙 https://docs.koel.dev for the official documentation.
Feeling generous and want to support Koel's development? Check out 
https://github.com/users/phanan/sponsorship 🤗
Thanks for using Koel. You rock! 🤘

Next, initialize the database again with the following command:

php artisan koel:init

You should see the following output:

Attempting to install or upgrade Koel.
Remember, you can always install/upgrade manually following the guide here:
📙 https://docs.koel.dev

Generating app key
JWT secret exists -- skipping
Migrating database
Data seeded -- skipping
The absolute path to your media directory. If this is skipped (left blank) now, you can set it later via 
the web interface.

Media path []:
>

Now to front-end stuff
├── Installing Node modules in resources/assets directory

Next, create a logs directory and provide necessary permissions and ownership with the following command:

mkdir /var/www/html/koel/storage/logs
chown -R www-data:www-data /var/www/html/koel
chmod -R 755 /var/www/html/koel

Step 8 – Configure Nginx for Koel

Now, create a Nginx virtual host configuration file to serve Koel.

nano /etc/nginx/sites-available/koel.conf

Add the following lines:

server {
listen 80 default_server;
server_name koel.example.com;
root /var/www/html/koel;
index index.html index.htm index.php;

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

location ~ \.php$ {
fastcgi_pass unix:/run/php/php7.4-fpm.sock;
fastcgi_index index.php;
fastcgi_read_timeout 240;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_split_path_info ^(.+.php)(/.+)$;
}
}

Save and close the file, then activate the Nginx virtual host file with the following command:

ln -s /etc/nginx/sites-available/koel.conf /etc/nginx/sites-enabled/

Next, restart the Nginx and PHP-FPM services to apply the changes:

systemctl restart nginx
systemctl restart php7.4-fpm

Step 9 – Access Koel Web UI

Now, open your web browser and access the Koel UI using the URL http://koel.example.com. You will be redirected to the Koel login page:

Provide your admin email and password which you have set in .env file, then click on the Log In button. You should see the Koel default dashboard in the following page:

Conclusion

Congratulations! You have successfully installed and configured a Koel audio streaming server on Ubuntu 20.04. Now, you can host your own music streaming server and access it over the Internet. Try Koel on VPS Hosting from Atlantic.Net using the tutorial above!

Get A Free To Use Cloud VPS

Free Tier Includes:
G3.2GB Cloud VPS Free to Use for One Year
50 GB of Block Storage Free to Use for One Year
50 GB of Snapshots Free to Use for One Year


Looking for a Hosting Solution?

We Provide Cloud, Dedicated, & Colocation.

  • Seven Global Data Center Locations.
  • Flexible Private, Public, & Hybrid Hosting.
  • 24x7x365 Security, Support, & Monitoring.
Contact Us Now! Med Tech Award FTC
SOC Audit HIPAA Audit HITECH Audit

Recent Posts

Get started with 12 months of free cloud VPS hosting

Free Tier includes:
G3.2GB Cloud VPS Server Free to Use for One Year
50 GB of Block Storage Free to Use for One Year
50 GB of Snapshots Free to Use for One Year


New York, NY

100 Delawanna Ave, Suite 1

Clifton, NJ 07014

United States

San Francisco, CA

2820 Northwestern Pkwy,

Santa Clara, CA 95051

United States

Dallas, TX

2323 Bryan Street,

Dallas, Texas 75201

United States

Ashburn, VA

1807 Michael Faraday Ct,

Reston, VA 20190

United States

Orlando, FL

440 W Kennedy Blvd, Suite 3

Orlando, FL 32810

United States

Toronto, Canada

20 Pullman Ct, Scarborough,

Ontario M1X 1E4

Canada

London, UK

14 Liverpool Road, Slough,

Berkshire SL1 4QZ

United Kingdom

Resources