Home / How To / How to install Koel Music Streaming Server on Ubuntu 18.04

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 user using root.

  • Make sure everything is up to date.

      $ sudo  apt update &&  sudo  apt upgrade 
  • Get packages that your system needs.

      $ sudo  apt install ca certificate  curl  unzip build-essential libpng-dev gnupg2 lsb-release ufw  -y 

    Some 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 must allow SSH ports otherwise we will be locked from our server.

  $ sudo  ufw allow OpenSSH 

Enable firewall.

  $ sudo  ufw enable 

Allow ports HTTP and HTTPS.

  $ sudo  ufw allow http 
$ sudo ufw allow https

Check the status of the firewall.

  $ sudo  ufw status 

You would 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) [19659022] 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 install Node 10.x instead of the latest 12.x because Koel packages some outdated libraries that 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 installed correctly .

  $ 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.listPO19659017vard$ sudo apt update && sudo apt install -y yarn

Check if the yarn is working properly.

  $ yarn    - version 

You should see a similar output.

  1  .19.1 

Install PHP [19659063] Install PHP 7.2 with all necessary add-ons.

  $ 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 properly.

  $ 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 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 that commands for running and using MariaDB are the same as for MySQL. To install MariaDB, the following commands are issued.

  $ sudo  apt install mariadb server 

Check if MariaDB installed correctly.

  $ mysql    - version 

You should see the following output.

  mysql Ver  15  .1 Distribute  10  .1.41-MariaDB,  for  debian-linux-gnu (x86_64) using readline  5  .2 

Run the following command to perform the default configuration such as providing a root password, removing anonymous users, rejecting remote root logins, and dropping test tables. Enter yes for everything and set a root password.

  $ sudo  mysql_secure_installation 

There is a warning setting the root password. By default, MariaDB allows system root users to log in to MariaDB without a password. But if you are going to use a third-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 reset the root password, first enter the MySQL prompt with the following command.

  $ sudo  mysql  -u  root 

Now enter the following commands to disable plugin authentication.

  use  mysql; 
update user set plugin = & # 39; & # 39; where Users = & # 39; root & # 39; ;
flush privileges ;
exit

After this restart of your MariaDB service.

  $ sudo  systemctl  restart  mariadb.service 

That's it. The next time you want to log into MySQL, use the following command

  $ sudo  mysql  -u  root  -p 

Enter your root password when prompted.

Configuring MariaDB for Koel

Now we need to create a database to use for the Koel application. To make that login to the MySQL prompt. We assume that you are using the MariaDB default authentication method (ie without using root passwords) for the rest of the tutorial.

  $ sudo  mysql  -u  root 

Once prompted, enter the following commands that will create a database named koelmusic and a database user named [19659113] koeluser and grant it access to the database.

  mysql>  CREATE    DATABASE  cool music; 
mysql> CREATE USER & # 39; coolers & # 39; @ & # 39; localhost & # 39; IDENTIFIED BY & # 39; yourpassword & # 39; ;
mysql> GRANT ALL PRIVILEGES ON cool music. * TO & # 39; coolers & # 39; @ & # 39; localhost & # 39; ;
mysql> FLUSH PRIVILEGES ;
mysql> exit

Install Nginx

Install Nginx server.

  $ sudo  apt install nginx 

Check if it is working properly.

  $ nginx    -v 

You should see the following output.

  nginx version: nginx / 1.14.0 (Ubuntu) 

Run the following command to add a Koel configuration file.

  $ sudo  nano /etc/nginx/sites-available/koel.confebrit19659142vard Paste the following code into the editor. 

  server  {
listen *: 80;
server name cool.example.com;
root / var / www / cool;
index index .php;
?
gzip on;
gzip_types text / plain text / css application / x-javascript text / xml application / xml application / xml + rss text / j avascript application / json;
gzip_comp_level 9;
?
# Whitelist only index.php, robots.txt and some special routes
if ($ request_uri ! ~ ^ / $ | index . php | robots . txt | (public | api) / | remote | api-docs | sw . js) {
back 404;
}
?
location / media / {
internal ;
[19459106
alias $ upstream_http_x_media_root;
?
access_log /var/log/nginx/koel.access.log;
error_log /var/log/nginx/koel.error.log;ebrit19659022]}
?
location / {
try_files $ uri $ uri // Chapter19459072strongindex Chapter19459006 Edward.vud19459038facephp ??? $ arg;
}
?
location ~ . php $ {
try_files $ uri $ uri // Chapter19459072strongindexvud19459006vard.vud19459038vardphp ??? 19459006achte $ args; vud19659022] fast_arg ] $ fastcgi_;
fastcgi_param PATH_TRANSLATED $ document_root $ fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $ document_root $ fastcgi_gi5_script_19522_script / var / run / php / php7. ] ^ (. + . php) ( /.+ ) $;

fastcgi_intercept_errors on;
include fastcgi_params;
}
}

This file assumes that we will install Koel to the domain koel.example.com and in the directory / var /www/koelvud19659198achte.vud19659199??Enable this configuration file by linking it to the sites-enabled directory.

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

Test the configuration.

  $ sudo  nginx  -t 

You should see the following output indicating your configuration is correct.

  nginx: configuration file /etc/nginx/nginx.conf syntax is ok 
nginx: configuration file /etc/nginx/nginx.conf test successful

Reload Nginx service.

  $ sudo  systemctl r eload nginx 

Install Composer

This is the last thing we need before we proceed to the installation.

Enter the following commands to install Composer.

  $ php    -r    "copy (& # 39; https: //getcomposer.org/installer&#39 ;, & # 39; composer-setup.php & # 39;);"  
$ php composer-setup.php
$ php -r "unlink (& # 39; composer-setup.php & # 39;);"
$ sudo etc. composer.phar / usr / local / bin / composer

Check if it works properly.

  $ composer    - version 

You should see the following output.

  Composer Version  1  .9.1  2019   -11-01 [19659071] 17 : 20: 17 

Install Koel

Create an empty document root directory for Koel.

  $ sudo    mkdir    -p  / var / www / koel [19659236]   -p    argument ensures that the parent catalogs   were    and   www    is created automatically if they do not exist. 

Navigate to the document root directory.

  $ cd  / var / www / koel 

Change the ownership of the document root to users [19659196] which is the non-root user we have used for the tutorial.

  $ sudo    chown    -R  user: user / var / www / koel 

Clone Koel Git repository and checkout latest version. You can check the latest version from its publisher page.

  $ git  clone  - recursive submodules  https://github.com/phanan/koel.git. 
$ git checkout v4.1.1

Install dependencies.

  $ composer  install 

Run the following command to set up the database and administrator account. Enter mysql as the database type, skip the port, and enter the database information we created above. For the media folder, you can specify something like / home / user / songs .

  $ php  artisan koel: init 

Change the ownership of the document root directory back to [19659195] www-data users.

  $ sudo    chown    -R  www-data: www-data / var / www / koel 

The setting is now complete. Open koel.example.com in your browser and log in with the credentials you created above and start streaming. Koel's website is also available via mobile.

Configure Koel

There are more details that you can configure by editing the .env file with the following command.

  $ sudo  nano /var/www/koel/.envebrit19659274_Nere you can enter your SMTP details, configure Youtube and Last.fm for Koel and do many more things. 

Reload the Nginx server to implement the changes.

If you want to reset your administrator password, you can do so by issuing the following command.

  $ php  artisan koel: admin: Change-password 

If you want to scan the media library for updated files, you can do so with the following command.

  $ php  artisan koel: sync 

You should see the following output.

  Cool sync started. 
953 / 953 [????????????????????????????] 100 % [19659022] Done! 944 new or updated song (s), 0 unchanged song (s), and 9 invalid file (s).

Attach the command with [19659113] -v flag which gives you more information as a synchronization error.

You can even set this command as a cron job, for example, to run every midnight. To do so, run the following command.

  $ crontab    -e 

Select 1 ( nano ) as editor.

Paste the following line at the end of the file.

  0 0 * * * cd / var / www / koel && / usr / bin / php artisan koel: sync> / dev / null 2> & 1 

Save the file by pressing Ctrl + X [19659114] and enter Y when prompted. Now your media library will sync every midnight.

For more things, see the official Koel documentation .

Setting HTTPS with Let's Encrypt

To use Let's Encrypt, we must install the package Certbot .

Add to archive.

  $ sudo  add-apt-repository ppa: certbot / certbot 

Install Certbot.

  $ sudo  apt install python-certbot-nginx 

Install the certificate.

  $ sudo  certbot  - nginx    -d  koel.example.com 

If this is your first time using the tool on this server, you must accept the terms and enter your e-mail address. Say no when asked if you want to share your email with the EFF foundation.

If successful, certbot will ask how to configure your HTTPS settings. 19659321] Choose whether you want to redirect HTTP traffic to HTTPS or remove HTTP access.
-------------------------------------------------- -------------------------------- ---
1 : None redirection - Make no further changes to the web server configuration.
2 : Redirect - Redirect all requests to secure HTTPS access. Select this for
new sites, or if you are sure your site is working on HTTPS. You can undo this
change by editing your web server & # 39; s configuration.
---------------------------------------------------- --------------------------- -----------
Select appropriate number [1-2] then [enter] (press & # 39; c & # 39; to cancel):

Select 2 and then hit ENTER . Your certificate is now installed and activated. Your certificate will be renewed automatically in 90 days.

Conclusion

This concludes our tutorial. You can stream media from your server to your heart's content.


Source link