How to Install Sonerezh Music Streaming Server on Ubuntu 16.04 with Apache or Nginx
Sonerezh is a self-hosted, web-based music streaming server written in PHP and HTML5. It’s lightweight compared to Subsonic which is written in Java. Sonerezh is open-source software, distributed under the terms of AGPL. This tutorial will show you how to install Sonerezh on Ubuntu 16.04 with Apache or Nginx.
Sonerezh features:
- Modern and simple-to-use web interface
- Playlist management: add titles, albums and artists to your playlists.
- Share music via the user management system
- Automatic metadata extraction and file import
- Auto-transcode to mp3
- Simple search engine
With Sonerezh, you can listen to your music from everywhere with a web browser and Internet connection.
To follow this tutorial, you will need to have LAMP or LEMP installed on Ubuntu 16.04. If you haven’t already done so, please check out the following tutorials.
- How to install LAMP (Apache, MariaDB, PHP7) on Ubuntu 16.04
- How to install LEMP (Nginx, MariaDB, PHP7-FPM) on Ubuntu 16.04
Once LAMP or LEMP is installed, come back here and read on.
Installing Sonerezh on Ubuntu 16.04
The latest stable version is Sonerezh 1.1.3, released on December 19th, 2016. You can download it with Git from Github repository.
Change directory to /var/www/
.
cd /var/www/
Install git
and use git to clone the Sonerezh from Github.
sudo apt install git sudo git clone --branch master https://github.com/Sonerezh/sonerezh.git
Set web server (www-data
) as the owner of the new directory.
sudo chown www-data:www-data /var/www/sonerezh/ -R
Create MariaDB/MySQL Database for Sonerezh
Log into MariaDB/MySQL database server with the following command:
mysql -u root -p
Then create a database for Sonerezh. This tutorial name the database sonerezh
. You can use whatever name you like.
create database sonerezh;
Create the database user and grant this user all privileges on the sonerezh database. Replace your-password
with your preferred password.
grant all privileges on sonerezh.* to sonerezh@localhost identified by 'your-password';
Flush privileges and exit.
flush privileges; exit;
Setting up Apache Virtual Host
We will create a sonerezh.conf
file in /etc/apache2/sites-available/
directory.
sudo nano /etc/apache2/sites-available/sonerezh.conf
Copy and paste the following lines in the file. Replace the red text with your preferred domain name. You also need to create an A record for the domain name. If you install Sonerezh on your home server, then you also need to configure port forwarding in the router.
<VirtualHost *:80>
ServerName music.your-domain.com
DocumentRoot /var/www/sonerezh
<Directory /var/www/sonerezh>
Options -Indexes
AllowOverride All
# Apache 2.2.x
<IfModule !mod_authz_core.c>
Order Allow,Deny
Allow from all
</IfModule>
# Apache 2.4.x
<IfModule mod_authz_core.c>
Require all granted
</IfModule>
</Directory>
CustomLog /var/log/apache2/sonerezh-access.log "Combined"
ErrorLog /var/log/apache2/sonerezh-error.log
</VirtualHost>
Save and close the file.
sudo a2ensite sonerezh.conf
Then enable mod_rewrite module and reload Apache web server for the changes to take effect.
sudo a2enmod rewrite sudo systemctl reload apache2
Now go to music.your-domain.com/install
. You will see the Sonerezh web installer, which lists some requirements. To satisfy these requirements, run the following command.
sudo apt install php7.0-gd libav-tools
Enabling HTTPS (Apache)
To finish the installation, you need to enter the database details and create an admin account. But before doing that, let’s install a free TLS certificate from Let’s Encrypt so that what you enter in the web installer won’t be sniffed.
Install certbot (Let’s Encrypt) client.
sudo apt install letsencrypt python-letsencrypt-apache
Now issue the following command to obtain a free TLS/SSL certificate. Replace the red-colored text with your actual data.
sudo letsencrypt --apache --agree-tos --redirect --hsts --email your-email-address -d music.your-domain.com
Explanation:
- –apache: Use the Apache plugin to automatically obtain and install the certificate.
- –agree-tos: Agree to the terms of service.
- –redirect: Redirect all HTTP traffic to HTTPS for the virtual host
- –hsts: Forcing browser to always use TLS.
Within a few seconds, you should see the following, which means a free TLS/SSL certificate is obtained and installed on your Apache server.
The default TLS/SSL configurations score A+ in SSL Labs test.
Setting up Nginx Server Block
If you use Nginx instead of Apache, then create a Nginx server block file.
sudo nano /etc/nginx/conf.d/sonerezh.conf
Copy and paste the following lines in the file. Replace the red text with your preferred domain name. You also need to create an A record for the domain name. If you install Sonerezh on your home server, then you also need to configure port forwarding in the router.
server {
listen 80;
server_name music.your-domain.com;
root /var/www/sonerezh/app/webroot;
index index.php;
location / {
try_files $uri $uri/ /index.php?$args;
expires 14d;
add_header Cache-Control 'public';
}
# The section below handle the thumbnails cache, on the client (browser)
# side (optional but recommended)
location ~* /([^/]+_[0-9]+x[0-9]+(@[0-9]+x)?\.[a-z]+)$ {
try_files /img/resized/$1 /index.php?$args;
add_header Cache-Control 'public';
expires 14d;
access_log off;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_index index.php;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
include fastcgi.conf;
# If fastcgi.conf is not available on your platform you may want to
# uncomment the following line
#fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
Save and close the file. Then test the configuration.
sudo nginx -t
If the test is successful, reload Nginx.
sudo systemctl reload nginx
Now go to music.your-domain.com/install
. You will see the Sonerezh web installer, which lists some requirements. To satisfy these requirements, run the following command.
sudo apt install php7.0-gd libav-tools
Enabling HTTPS (Nginx)
To finish the installation, you need to enter the database details and create an admin account. But before doing that, let’s install a free TLS certificate from Let’s Encrypt so that what you enter in the web installer won’t be sniffed.
Install certbot (Let’s Encrypt) client.
sudo apt install letsencrypt
Now issue the following command to obtain a free TLS/SSL certificate. Replace the red-colored text with your actual data.
sudo letsencrypt certonly --webroot --agree-tos --email your-email-address -d music.your-domain.com -w /var/www/sonerezh/app/webroot/
Within a few seconds, you should see the following, which means a free TLS/SSL certificate is obtained.
Now edit the Sonerezh server block file to configure TLS.
sudo nano /etc/nginx/conf.d/sonerezh.conf
Change the configurations to the following.
server { listen 80; server_name music.your-domain.com; return 301 https://$server_name$request_uri; } server { listen 443 ssl http2; server_name music.your-domain.com; root /var/www/sonerezh/app/webroot; ssl_certificate /etc/letsencrypt/live/music.your-domain.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/music.your-domain.com/privkey.pem; ssl_session_timeout 1d; ssl_session_cache shared:SSL:50m; ssl_session_tickets off; # modern configuration. tweak to your needs. ssl_protocols TLSv1.2; ssl_ciphers 'ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256'; ssl_prefer_server_ciphers on; # HSTS (ngx_http_headers_module is required) (15768000 seconds = 6 months) add_header Strict-Transport-Security max-age=15768000; # OCSP Stapling --- # fetch OCSP records from URL in ssl_certificate and cache them ssl_stapling on; ssl_stapling_verify on; index index.php; location / { try_files $uri $uri/ /index.php?$args; expires 14d; add_header Cache-Control 'public'; } # The section below handle the thumbnails cache, on the client (browser) # side (optional but recommended) location ~* /([^/]+_[0-9]+x[0-9]+(@[0-9]+x)?\.[a-z]+)$ { try_files /img/resized/$1 /index.php?$args; add_header Cache-Control 'public'; expires 14d; access_log off; } location ~ \.php$ { try_files $uri =404; fastcgi_index index.php; fastcgi_pass unix:/run/php/php7.0-fpm.sock; include fastcgi.conf; # If fastcgi.conf is not available on your platform you may want to # uncomment the following line #fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; } }
Save and close the file. Then test the configuration.
sudo nginx -t
If the test is successful, reload Nginx.
sudo systemctl reload nginx
Finish the Installation
Now your connection is HTTPS-enabled, you can enter your database details in the web installer. And also create an admin account and specify the music folder.
Sonerezh Web-based Music Streaming Server
Auto Renew Certificate
To automatically renew Let’s Encrypt certificate, edit root user’s crontab file.
sudo crontab -e
Add the following line at the end of the file.
@daily letsencrypt renew --quiet && systemctl reload apache2
If you use Nginx, then replace apache2 with nginx.
@daily letsencrypt renew --quiet && systemctl reload nginx
Reloading is needed for the web server to pick up the new certificate.
That’s it! I hope this tutorial helped you install Sonerezh music streaming server on Ubuntu 16.04 with Apache or Nginx. You may also want to check out how to install Subsonic music streaming server.
I love how all these tutorials work fine for him, but almost none of them work for me…
Ye not working for me either…
I get a 502 error, the favicon shows though…