How to install Sonerezh on Ubuntu 14.04

install-sonerezh-on-an-ubuntu-14-04-vpsIn this guide, we will explain how to install Sonerezh on an Ubuntu 14.04 VPS with MariaDB, PHP-FPM and Nginx. Sonerezh is an open source self-hosted application for streaming music. Sonerezh is build with PHP on top of the CakePHP framework and with the latest web technologies. 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

Update the system and install necessary packages

[user]$ sudo apt-get update && sudo apt-get -y upgrade

In order to convert the tracks we will need the avconv command which is included in the libav-tools package

[user]$ sudo apt-get install software-properties-common libav-tools nano git

Install MariaDB 10.1

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.1/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 our Sonerezh installation.

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

Install PHP, composer and required PHP modules

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

[user]$ sudo add-apt-repository -y ppa:ondrej/php5-5.6
[user]$ sudo apt-get update
[user]$ sudo apt-get -y install php5-fpm php5-cli php5-gd php5-mysqlnd php5-mcrypt php5-curl php5-intl

PHP-FPM configuration

Create a new PHP-FPM pool for your user:

[user]$ sudo nano /etc/php5/fpm/pool.d/your_username.conf
[your_username]
user = your_username
group = your_username
listen = /var/run/php5-fpm-your_username.sock
listen.owner = your_username
listen.group = your_username
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_username with your username.

Restart PHP-FPM:

[user]$ sudo service php5-fpm restart

Clone Sonerezh

Create a root directory for your Sonerezh installation using the following command:

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

Clone the github repository

git clone --branch master https://github.com/Sonerezh/sonerezh.git ~/mySonerezhSite.com/public_html

Create a root directory for your music data

mkdir -p /home/your_username/mySonerezhSite.com/public_html/Music

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

Create a new Nginx server block with the following content:

[user]$ sudo nano /etc/nginx/sites-available/mySonerezhSite.com
server {
    listen      80;
    server_name mySonerezhSite.com;
    root        /home/your_username/mySonerezhSite.com/public_html/app/webroot;

    access_log /home/your_username/mySonerezhSite.com/logs/access.log;
    error_log /home/your_username/mySonerezhSite.com/logs/error.log;

    index index.php;

    location / {
        try_files $uri $uri/ /index.php?$args;
        expires 14d;
        add_header Cache-Control 'public';
    }

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php5-fpm-your_username.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;
    }
}

Do not forget to change your_username with your username.

Activate the server block by creating a symbolic link :

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

Test the Nginx configuration and restart nginx:

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

Final steps

Open http://mySonerezh.com in your favorite web browser and you should see the Sonerezh install screen. Provide the database information, enter the path to your music data and follow the installation wizard instructions.


That’s it. You have successfully installed Sonerezh on your Ubuntu 14.04 VPS. For more information about how to manage your Sonerezh installation, please refer to the official Sonerezh 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.

Leave a Comment