Koel is a free and open source web based audio streaming server based on HTML5, ES6. It is written in Laravel on the server side and Vue on the client side.
Here, we will explain how to install Koel server with MariaDB, PHP-FPM and Nginx.
Prerequisites
- A server running Ubuntu 16.04.
- A non-root user with sudo privileges setup on your server.
- A static IP address 192.168.15.110 configure on your server.
Update the System
First, update your system to the latest stable version by running the following command:
sudo apt-get update -y
sudo apt-get upgrade -y
Once your system is up to date, you can proceed to the next step.
Install Required Packages
Before starting, you will need to install Nginx, MariaDB, PHP, composer, Nodejs and required PHP modules in your system.
You can install all those package by running the following command:
sudo apt-get install nginx mariadb-server php7.0-fpm php7.0-cli php7.0-gd php7.0-mysql php7.0-mcrypt php-pear php7.0-curl git -y
Once installation is complete, you will need to install composer. Composer is a dependency manager for PHP that can be used to install required libraries and dependencies for your project.
You can install it with the following command:
curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer
Once composer is installed, you will need to install the latest version of nodejs from the nodesource repository.
First, you will need to download the nodejs setup script. You can download it using the curl command:
curl -sL https://deb.nodesource.com/setup_6.x -o nodesource_setup.sh
Then, run the downloaded script with the following command:
sudo bash nodesource_setup.sh
The above script will add nodejs PPA and update local package cache.
Next, install nodejs with the following command:
sudo apt-get install nodejs
Once nodejs is installed, you can proceed to the next step.
Configure MariaDB for Koel
By default MariaDB installation is not secured, so you will need to secure it first.
You can secure it by running the mysql_secure_installation
script.
sudo mysql_secure_installation
Answer all the questions as shown below:
Enter current password for root (enter for none):
Change the root password? [Y/n] n
Remove anonymous users? [Y/n] Y
Disallow root login remotely? [Y/n] Y
Remove test database and access to it? [Y/n] Y
Reload privilege tables now? [Y/n] Y
Next, login to MariaDB console and create a database for the Koel:
mysql -u root -p
Enter your MariaDB root password and hit enter. Once you are logged in to your database, you need to create a database for Koel:
Run the following command to create a database for your Koel installation:
MariaDB [(none)]> CREATE DATABASE koeldb;
Next, create a new database user and provide the appropriate privileges to your database user over the database you have created.
MariaDB [(none)]> GRANT ALL PRIVILEGES ON user.* TO 'koeldb'@'localhost' IDENTIFIED BY 'password';
Next, run the following command to immediately apply the changes on the database privileges:
MariaDB [(none)]> FLUSH PRIVILEGES;
Next, exit from the Mysql with the following command:
MariaDB [(none)]> \q
Once database is configured, you can proceed to the next step.
Install Koel
You can download the latest version of the Koel source from GitHub.
You can clone Koel from GitHub repository with the following command:
cd /var/www/html
sudo git clone https://github.com/phanan/koel.git ~/myKoel.com/public_html
Next, you will need to install all npm packages:
sudo npm install
After installing npm packages, install all PHP dependencies using composer:
sudo composer install
Next, you will need to edit the .env
file:
sudo nano /var/www/html/.env
Change the database and admin details as shown belows:
ADMIN_EMAIL=koeladmin@example.com
ADMIN_NAME=koeladmin
ADMIN_PASSWORD=admin@123
DB_DATABASE=koeldb
DB_USERNAME=user
DB_PASSWORD=password
Save the file and initialize the database with the following command:
sudo php artisan init
Configure PHP-FPM
Next, you will need to configure PHP-FPM pool for www-data user.
To do so, create a new PHP-FPM pool for www-data user:
sudo nano /etc/php/7.0/fpm/pool.d/www-data.conf
Add the following lines:
[www-data]
user = www-data
group = www-data
listen = /var/run/php-fpm-www-data.sock
listen.owner = www-data
listen.group = www-data
listen.mode = 0666
pm = ondemand
pm.max_children = 5
pm.process_idle_timeout = 10s
pm.max_requests = 200
chdir = /
Save and close the file when you are finished, then restart PHP-FPM service with the following command:
sudo systemctl restart php7.0-fpm
Configure Nginx
Before starting, you will need to create a self signed ssl certificate for Nginx.
You can do this by running the following command:
sudo mkdir /etc/nginx/ssl
cd /etc/nginx/ssl
sudo openssl genrsa -des3 -passout pass:x -out koel-pass.key 2048
sudo openssl rsa -passin pass:x -in koel-pass.key -out koel.key
sudo openssl req -new -key koel.key -out koel.csr
sudo openssl x509 -req -days 365 -in koel.csr -signkey koel.key -out koel.crt
Next, you will need to create a virtual host server block for Nginx.
Create a new server block inside /etc/nginx/sites-available/
directory:
sudo nano /etc/nginx/sites-available/koel.conf
Add the following lines:
server {
listen 443 default;
server_name example.com;
root /var/www/html/public;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
ssl on;
ssl_certificate /etc/nginx/ssl/koel.crt;
ssl_certificate_key /etc/nginx/ssl/koel.key;
ssl_session_timeout 5m;
ssl_ciphers 'AES128+EECDH:AES128+EDH:!aNULL';
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
access_log /var/log/nginx/koel-access.log;
error_log /var/log/nginx/koel-error.log;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php-fpm-www-data.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors off;
fastcgi_buffer_size 16k;
fastcgi_buffers 4 16k;
}
location ~ /\.ht {
deny all;
}
}
server {
listen 80;
server_name example.com;
add_header Strict-Transport-Security max-age=2592000;
rewrite ^ https://$server_name$request_uri? permanent;
}
Save and close the file when you are finished, then activate the server block by creating a symbolic link :
sudo ln -s /etc/nginx/sites-available/koel.conf /etc/nginx/sites-enabled/
Next, test the Nginx for syntex error and restart Nginx with the following command:
sudo nginx -t
sudo systemctl restart nginx
#Access Koel Web Interface
Before accessing the Koel web interface, you will need to allow port 80 and 443 through UFW firewall.
By default UFW is disabled on your system, so you need to enable it first.
You can enable it with the following command:
sudo ufw enable
Once UFW firewall is enabled, you can allow port 80 and 443 by running the following command:
sudo ufw allow 80
sudo ufw allow 443
You can now check the status of UFW firewall by running the following command:
sudo ufw status
Next, open your favourite web browser and type the URL https://your-server-ip, you should see the Koel login screen.
Congratulations! You have successfully installed Koel on your Ubuntu 16.04 server.