Koel Music Server Ubuntu 16.04 Install Guide

Koel is a selfhosted music streaming service written in PHP and javascript with vue and laravel. This guide will go through the process of installing Koel on Ubuntu server 16.04 running under an NGINX webserver with a MariaDB sql database. Before we start, make sure you have a user with root or sudo privileges.

Koel must be installed at its own domain or sub domain. It will not work properly in a directory/URI.

Your music files must be located on the server allong with the application and NGINX.

Installation

Before installing Koel, we must install NGINX, PHP, MariaDB, and all the other dependencies.

NGINX

NGINX will be the main web server. Install it with the following commands:
sudo apt-get update
sudo apt-get install nginx

after that, you can verify that the install was successful by navigating to your servers IP or domain in a web browser. You should see the following:

nginx welcome page

Great, that's all we need to do for now with NGINX. If you'd like to set up Koel under a sub domain or secure it with SSL, you can head over to my NGINX guide.

MariaDB

The SQL database is MariaDB, a MySQL compatible SQL. To install the server and client, run the following commands:
sudo apt-get install mariadb-client mariadb-server
sudo mysql_secure_installation

The second command will bring up the following prompts. Follow the directions below.

Enter current password for root (enter for none):  # Hit enter
Set root password? [Y/n]                           # Y
New password:                                      # New Root database pass
Re-enter new password:                             # Repeat
Remove anonymous users? [Y/n]                      # Y
Disallow root login remotely? [Y/n]                # Y
Reload privilege tables now? [Y/n]                 # Y

Now we have to log in the server to create a database for Koel as well as a new user. Login by typing the following command then entering the password you set before.

mysql -u root -p
Enter passowrd:                             # Enter your root database password

Once you are at the MariaDB command prompt, enter the following commands to create a database, user and set permissions:

CREATE DATABASE koel DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;
CREATE USER 'koel'@'localhost' IDENTIFIED BY 'koelpass';
GRANT ALL PRIVILEGES ON koel.* TO 'koel'@'localhost' WITH GRANT OPTION;
exit;

Now you have a database koel and a user koel with the password koelpass.

Dependecies

Finally we can install the rest of the dependencies. Run the following commands:
cd ~
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
sudo echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo curl -sL https://deb.nodesource.com/setup_6.x | bash - && sudo apt-get update && sudo apt-get install -y php7.0 php7.0-mysql php7.0-zip php7.0-xml php7.0-tidy php7.0-mbstring php7.0-fpm php7.0-common zip unzip git g++
curl -sS https://getcomposer.org/installer -o composer-setup.php
sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer && composer -V

You should see Composer version x.x.x in the console if it was successful.

Koel

Now we are finally ready to install Koel. Run the following commands to download Koel to your home directory:
cd ~
git clone https://github.com/phanan/koel.git music
cd music
composer install
yarn

Configuration

NGINX

Make NGINX work with PHP by editing the site config with the following command:
sudo nano /etc/nginx/sites-enabled/default

Now replace the contents of that file with the following. Note that if you want SSL, subdomains or any other special config, the server block that you will need will be different. See my NGINX guide for more details.

server {
    listen 80 default_server;
    listen [::]:80 default_server;

    root /var/www/html;
    index index.php index.html index.htm index.nginx-debian.html;

    server_name _;

    location / {
        try_files $uri $uri/ =404;
    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.0-fpm.sock;
    }

    location ~ /\.ht {
        deny all;
    }
}

Save and exit and then reload nginx by typing:

sudo service nginx reload

Koel

Now we have to setup Koel to use our database info as well as tell it what the first users account info should be. Edit the .env file and fill in the variables noted below: ```bash cd ~/music nano .env ```
DB_CONNECTION=mysql
DB_HOST=localhost
DB_DATABASE=koel
DB_USERNAME=koel
DB_PASSWORD=koelpass
ADMIN_EMAIL=your-email
ADMIN_NAME=your-name
ADMIN_PASSWORD=your-pass

Now you can save and close the file. Run the next commands to initialize the application, move it into the web root and set the permissions:

sudo rm * /var/www/html && sudo cp -R * /var/www/html 
sudo chown -R www-data:www-data /var/www/html*
cd /var/www/html
sudo php artisan koel:init

And now you should be good to go! Head over to http://<your-ip/domain> in your browser and sign in with the credentials you setup earlier. Click settings and put in your music directory the scan. Give it a moment and then you'll be able to enjoy your music off your server.

Email me with any suggestions to improve the tutorial!