X
    Categories: Tutorials

How to install Koel on Ubuntu 14.04

In this article, we will explain how to install Koel on an Ubuntu 14.04 VPS with MariaDB, PHP-FPM and Nginx. Koel is an audio streaming service written in Vue at the client side and Laravel on server side. This guide should work on other Linux VPS systems as well but was tested and written for an Ubuntu 14.04 VPS.

Login to your VPS via SSH

ssh user@vps_IP

Update the system and install necessary packages

[user]$ sudo apt-get update && sudo apt-get -y upgrade
[user]$ sudo apt-get install software-properties-common git nano

Install MariaDB 10.0

To add the MariaDB repository to your sources list and install the latest MariaDB server, run the following commands:

[user]$ sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xcbcb082a1bb943db
[user]$ sudo add-apt-repository 'deb http://ftp.osuosl.org/pub/mariadb/repo/10.0/ubuntu trusty main'
[user]$ sudo apt-get update
[user]$ sudo apt-get install -y mariadb-server

When the installation is complete, run the following command to secure your installation:

[user]$ mysql_secure_installation

Next, we need to create a database for the Koel installation.

[user]$ mysql -uroot -p
MariaDB [(none)]> CREATE DATABASE koeldb;
MariaDB [(none)]> GRANT ALL PRIVILEGES ON koeluser.* TO 'koeldb'@'localhost' IDENTIFIED BY 'koeluserpasswd';
MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> \q

Install PHP, composer and required PHP modules

To install the latest stable version of PHP version 7 and all necessary modules, run:

[user]$ LC_ALL=en_US.UTF-8 sudo add-apt-repository -y ppa:ondrej/php
[user]$ sudo apt-get update
[user]$ sudo apt-get -y install php7.0-fpm php7.0-cli php7.0-gd php7.0-mysql php7.0-mcrypt php-pear php7.0-curl

Composer is a dependency manager for PHP with which you can install packages. Composer will pull in all the required libraries and dependencies you need for your project.

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

Install Node.Js

We will install the latest nodejs package from the nodesource repository.

[user]$ curl -sL https://deb.nodesource.com/setup_5.x | sudo -E bash -
[user]$ sudo apt-get install -y nodejs

Install Koel

Create a root directory for your Koel using the following command:

[user]$ mkdir -p ~/myKoel.com/{public_html,logs}

Clone the project repository from GitHub:

[user]$ git clone https://github.com/phanan/koel.git ~/myKoel.com/public_html

Change to public_html the directory:

[user]$ cd  ~/myKoel.com/public_html

Run npm to install all npm packages including bower and gulp:

[user]$ npm install

and install all PHP dependencies using composer

[user]$ composer install

Edit the .env file with the database and admin details.

[user]$ nano ~/myKoel.com/public_html/.env
ADMIN_EMAIL=admin@myKoel.com
ADMIN_NAME=admin
ADMIN_PASSWORD=adminpasswd

DB_DATABASE=koeldb
DB_USERNAME=koeluser
DB_PASSWORD=koeluserpasswd

Finally initialize the database with:

[user]$ php artisan init

PHP-FPM configuration

Create a new PHP-FPM pool for your user:

[user]$ sudo nano /etc/php/7.0/fpm/pool.d/your_user.conf
[your_user]
user = your_user
group = your_user
listen = /var/run/php-fpm-your_user.sock
listen.owner = your_user
listen.group = your_user
listen.mode = 0666
pm = ondemand
pm.max_children = 5
pm.process_idle_timeout = 10s
pm.max_requests = 200
chdir = /

Do not forget to change your_user with your username.

Restart PHP-FPM:

[user]$ sudo service php7.0-fpm restart

Install and configure Nginx

Ubuntu 14.04 comes with Nginx version 1.4, to install the latest stable version of Nginx version 1.8, run:

[user]$ sudo add-apt-repository -y ppa:nginx/stable
[user]$ sudo apt-get update
[user]$ sudo apt-get -y install nginx

Generate a self signed ssl certificate:

[user]$ sudo mkdir -p /etc/nginx/ssl
[user]$ cd /etc/nginx/ssl
[user]$ sudo openssl genrsa -des3 -passout pass:x -out koel.pass.key 2048
[user]$ sudo openssl rsa -passin pass:x -in koel.pass.key -out koel.key
[user]$ sudo rm koel.pass.key
[user]$ sudo openssl req -new -key koel.key -out koel.csr
[user]$ sudo openssl x509 -req -days 365 -in koel.csr -signkey koel.key -out koel.crt

If you don’t want to get warnings associated with self-signed SSL Certificates, you can purchase a trusted SSL certificate here.

Next, create a new Nginx server block:

[user]$ sudo nano /etc/nginx/sites-available/myKoel.com
server {
    listen      443 default;
    server_name myKoel.com;
    root /home/your_user/myKoel.com/public_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-your_user.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 myKoel.com;

    add_header Strict-Transport-Security max-age=2592000;
    rewrite ^ https://$server_name$request_uri? permanent;
}

Do not forget to change your_user with your username.

Activate the server block by creating a symbolic link :

[user]$ sudo ln -s /etc/nginx/sites-available/myKoel.com /etc/nginx/sites-enabled/myKoel.com

Test the Nginx configuration and restart nginx:

[user]$ sudo nginx -t
[user]$ sudo service nginx restart

Open https://myKoel.com/login in your favorite web browser and you should see the Koel login screen. That’s it. You have successfully installed Koel on your Ubuntu 14.04 VPS. For more information about how to manage your Koel installation, please refer to the official Koel documentation.


Of course you don’t have to do any of this if you use one of our Linux VPS Hosting services, in which case you can simply ask our expert Linux admins to setup this for you. They are available 24×7 and will take care of your request immediately.

PS. If you liked this post please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.

View Comments

  • One of your steps is wrong. The command for cloning the Git repository is for another project. Incorrect: git clone https://github.com/cachethq/Cachet.git ~/myKoel.com/public_html Correct: git clone https://github.com/phanan/koel ~/myKoel.com/public_html