How to Install Koel Music Streaming Server on Ubuntu 18.04
Koel is a web-based personal audio streaming app written in Vue.js on the client-side and Laravel on the server-side. This tutorial will cover how to install Koel on Ubuntu 18.04 based server.
Prerequisites
-
A server running Ubuntu 18.04.
-
A non-root sudo user.
-
Make sure everything is updated.
$ sudo apt update && sudo apt upgrade
-
Few packages that your system needs.
$ sudo apt install ca-certificates curl unzip build-essential libpng-dev gnupg2 lsb-release ufw -ySome of these packages may already be installed on your system.
Configure Firewall
The first step is to configure the firewall. Before we enable the firewall, we need to allow SSH ports otherwise we will get locked out of our server.
$ sudo ufw allow OpenSSH
Enable the firewall.
$ sudo ufw enable
Allow HTTP and HTTPS ports.
$ sudo ufw allow http
$ sudo ufw allow https
Check the status of the firewall.
$ sudo ufw status
You should see a similar output.
Status: active
To Action From
-- ------ ----
OpenSSH ALLOW Anywhere
80/tcp ALLOW Anywhere
443/tcp ALLOW Anywhere
OpenSSH (v6) ALLOW Anywhere (v6)
80/tcp (v6) ALLOW Anywhere (v6)
443/tcp (v6) ALLOW Anywhere (v6)
Install Git
We will start by installing Git.
$ sudo apt install git -y
$ git config --global user.name "Your Name"
$ git config --global user.email "[email protected]"
Install Node.js
We will be installing Node 10.x instead of the latest 12.x because Koel packages some outdated libraries which are not compatible with Node 12.
curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
sudo apt install -y nodejs
Check if Node is properly installed.
$ node --version
You should see a similar output.
v10.17.0
Install Yarn
Install the Yarn package manager.
$ curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
$ echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
$ sudo apt update && sudo apt install -y yarn
Check if Yarn is working correctly.
$ yarn --version
You should see a similar output.
1.19.1
Install PHP
Install PHP 7.2 with all its required extensions.
$ sudo apt install -y php7.2-fpm php7.2-mbstring php7.2-bcmath php7.2-xml php7.2-mysql php7.2-curl php7.2-zip
Check if PHP is working correctly.
$ php --version
You should see a similar output.
PHP 7.2.24-1+ubuntu18.04.1+deb.sury.org+1 (cli) (built: Oct 24 2019 18:29:11) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.2.24-1+ubuntu18.04.1+deb.sury.org+1, Copyright (c) 1999-2018, by Zend Technologies
Install MariaDB
MariaDB is a drop-in replacement for MySQL which means commands to run and operate MariaDB are the same as those for MySQL. To install MariaDB issue the following commands.
$ sudo apt install mariadb-server
Check if MariaDB installed correctly.
$ mysql --version
You should see the following output.
mysql Ver 15.1 Distrib 10.1.41-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2
Run the following command to perform default configuration such as giving a root password, removing anonymous users, disallowing root login remotely and dropping test tables. Enter yes for everything and set up a root password.
$ sudo mysql_secure_installation
There is a caveat with setting up the root password. MariaDB by default allows system root users to log in to MariaDB without a password. But if you are going to use a 3rd party application to access via root, a password is a must otherwise apps like PHPMyAdmin will fail. For this, you need to disable the plugin-based authentication which is the default option on MariaDB.
To Disable plugin authentication and restore the root password, enter the MySQL prompt first by using the following command.
$ sudo mysql -u root
Now enter the following commands to disable the plugin authentication.
use mysql;
update user set plugin='' where User='root';
flush privileges;
exit
After this restart your MariaDB service.
$ sudo systemctl restart mariadb.service
That's it. Next time you want to login to MySQL, use the following command
$ sudo mysql -u root -p
Enter your root password when prompted.
Configure MariaDB for Koel
Now we need to set up a database to use for the Koel application. To do that login to MySQL prompt. We will assume that you are using the default authentication method of MariaDB ( i.e. without using root password) for the rest of the tutorial.
$ sudo mysql -u root
Once at the prompt, enter the following commands which will set up a database named koelmusic and a database user named koeluser and grant it access to the database.
mysql> CREATE DATABASE koelmusic;
mysql> CREATE USER 'koeluser'@'localhost' IDENTIFIED BY 'yourpassword';
mysql> GRANT ALL PRIVILEGES ON koelmusic.* TO 'koeluser'@'localhost';
mysql> FLUSH PRIVILEGES;
mysql> exit
Install Nginx
Install Nginx server.
$ sudo apt install nginx
Check if it is working correctly.
$ nginx