Moode Forum
[How to do instruction] moOde and Pi-Hole on Nginx - Printable Version

+- Moode Forum (https://moodeaudio.org/forum)
+-- Forum: moOde audio player (https://moodeaudio.org/forum/forumdisplay.php?fid=3)
+--- Forum: FAQ and Guides (https://moodeaudio.org/forum/forumdisplay.php?fid=9)
+--- Thread: [How to do instruction] moOde and Pi-Hole on Nginx (/showthread.php?tid=1938)

Pages: 1 2 3


moOde and Pi-Hole on Nginx - TookaFace - 11-30-2019

Just a little how-to for running Pi-Hole with moOde on Nginx web server.

Works for moOde 6.4 and higher
- Update repo:
Code:
sudo apt-get update -y

    - Install Pi-Hole:
Code:
curl -sSL https://install.pi-hole.net | bash

     - When prompted, answer Off to that question:
Code:
Do you wish to install the web server (lighttpd) and required PHP modules?
Off

    - Once the installation is complete, open this file:
Code:
sudo nano /etc/nginx/sites-available/default

    - Delete all contents and copy that instead:
Code:
server {
   listen 8080 default_server;
   listen [::]:8080 default_server;

   root /var/www/html;
   server_name _;
   autoindex off;
   error_page 404 /pihole/index.php;

   index pihole/index.php index.php index.html index.htm;

   location / {
       expires max;
       try_files $uri $uri/ =404;
   }

   location ~ \.php$ {
       include fastcgi_params;
       fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
       fastcgi_pass unix:/run/php/php7.3-fpm.sock;
       fastcgi_param FQDN true;
#        auth_basic "Restricted"; # For Basic Auth
#        auth_basic_user_file /etc/nginx/.htpasswd; # For Basic Auth
   }

   location /*.js {
       index pihole/index.js;
#        auth_basic "Restricted"; # For Basic Auth
#        auth_basic_user_file /etc/nginx/.htpasswd; # For Basic Auth
   }

   location /admin {
       root /var/www/html;
       index index.php index.html index.htm;
#        auth_basic "Restricted"; # For Basic Auth
#        auth_basic_user_file /etc/nginx/.htpasswd; # For Basic Auth
   }

   location ~ /\.ht {
       deny all;
   }
}

    - Set rights for Pi-Hole folder and add pihole user to www-data group:
Code:
sudo chown -R www-data:www-data /var/www/html
sudo chmod -R 755 /var/www/html
sudo usermod -aG pihole www-data

    - Open this file:
Code:
sudo nano -l /etc/nginx/nginx.conf

    - And uncomment line 64 (include /etc/nginx/sites-enabled/*):
Code:
user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
    worker_connections 768;
    # multi_accept on;
}

http {

    ##
    # Basic Settings
    ##

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;
    # server_tokens off;

    # server_names_hash_bucket_size 64;
    # server_name_in_redirect off;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;
    client_max_body_size 8M;

    ##
    # SSL Settings
    ##

    #ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
    #ssl_prefer_server_ciphers on;

    ##
    # Logging Settings
    ##

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    ##
    # Gzip Settings
    ##

    gzip on;
    gzip_disable "msie6";

    # gzip_vary on;
    # gzip_proxied any;
    # gzip_comp_level 6;
    # gzip_buffers 16 8k;
    # gzip_http_version 1.1;
    # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

    ##
    # Virtual Host Configs
    ##

    #include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;

    ##
    # moOde UI server
    ##

    server {
        listen 80;

        location / {
            root /var/www;
            index index.html index.php;
            try_files $uri $uri/ /coverart.php;
        }

        location /imagesw/ {
            root /var/local/www;
        }

        # php-fpm
        location ~ \.php$ {
            root /var/www;
            fastcgi_pass unix:/run/php/php7.3-fpm.sock;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $request_filename;
            include fastcgi_params;
        }
    }
}

    - Restart PHP and Nginx:
Code:
sudo systemctl restart php7.3-fpm.service
sudo systemctl restart nginx

    - At this point, you should can access to Pi-Hole:
Code:
http://pi.hole:8080/admin/

    - To finish, update moOde database:
Code:
sudo sqlite3 "/var/local/www/db/moode-sqlite3.db" "DROP TRIGGER IF EXISTS ro_columns"
sudo sqlite3 "/var/local/www/db/moode-sqlite3.db" "UPDATE cfg_hash SET VALUE = '$(md5sum  /etc/nginx/nginx.conf | cut -d " " -f1)' WHERE PARAM = '/etc/nginx/nginx.conf'"
sudo sqlite3 "/var/local/www/db/moode-sqlite3.db" "CREATE TRIGGER ro_columns BEFORE UPDATE OF param, value, [action] ON cfg_hash FOR EACH ROW BEGIN SELECT RAISE(ABORT, 'read only'); END;"

    - Reboot.


RE: moOde and Pi-Hole on Nginx - Jempie - 06-19-2020

(11-30-2019, 04:37 PM)TookaFace Wrote: Just a little how-to for running Pi-Hole with moOde on Nginx web server (based on moOde 6.4/6.4.1 version).

    - Install Pi-Hole:
Code:
curl -sSL https://install.pi-hole.net | bash

     - When prompted, answer Off to that question:
Code:
Do you wish to install the web server ?
Off

    - Once the installation is complete, open this file:
Code:
sudo nano /etc/nginx/sites-available/default

    - Delete all contents and copy that instead:
Code:
server {
       listen 8080 default_server;
       listen [::]:8080 default_server;

       root /var/www/html;
       server_name _;
       autoindex off;
       error_page 404 /pihole/index.php;

       index pihole/index.php index.php index.html index.htm;

       location / {
               expires max;
               try_files $uri $uri/ =404;
       }

       location ~ \.php$ {
               include snippets/fastcgi-php.conf;
               fastcgi_pass unix:/run/php/php7.3-fpm.sock;
               fastcgi_param FQDN true;
#                auth_basic "Restricted"; #For Basic Auth
#                auth_basic_user_file /etc/nginx/.htpasswd;  #For Basic Auth
       }

       location /*.js {
               index pihole/index.js;
#                auth_basic "Restricted"; #For Basic Auth
#                auth_basic_user_file /etc/nginx/.htpasswd;  #For Basic Auth
       }

       location /admin {
               root /var/www/html;
               index index.php index.html index.htm;
#                auth_basic "Restricted"; #For Basic Auth
#                auth_basic_user_file /etc/nginx/.htpasswd;  #For Basic Auth
       }

       location ~ /\.ht {
               deny all;
       }
}

    - Set rights for Pi-Hole folder:
Code:
sudo chown -R www-data:www-data /var/www/html
sudo chmod -R 755 /var/www/html

    - Open this file:
Code:
sudo nano -l /etc/nginx/nginx.conf

    - And uncomment line 64 (include /etc/nginx/sites-enabled/*):
Code:
user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
    worker_connections 768;
    # multi_accept on;
}

http {

    ##
    # Basic Settings
    ##

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;
    # server_tokens off;

    # server_names_hash_bucket_size 64;
    # server_name_in_redirect off;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;
    client_max_body_size 8M;

    ##
    # SSL Settings
    ##

    #ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
    #ssl_prefer_server_ciphers on;

    ##
    # Logging Settings
    ##

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    ##
    # Gzip Settings
    ##

    gzip on;
    gzip_disable "msie6";

    # gzip_vary on;
    # gzip_proxied any;
    # gzip_comp_level 6;
    # gzip_buffers 16 8k;
    # gzip_http_version 1.1;
    # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

    ##
    # Virtual Host Configs
    ##

    #include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;

    ##
    # moOde UI server
    ##

    server {
        listen 80;

        location / {
            root /var/www;
            index index.html index.php;
            try_files $uri $uri/ /coverart.php;
        }

        location /imagesw/ {
            root /var/local/www;
        }

        # php-fpm
        location ~ \.php$ {
            root /var/www;
            fastcgi_pass unix:/run/php/php7.3-fpm.sock;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $request_filename;
            include fastcgi_params;
        }
    }
}

    - Restart PHP and Nginx:
Code:
sudo systemctl restart php7.3-fpm.service
sudo systemctl restart nginx

    - At this point, you should can access to Pi-Hole:
Code:
http://pi.hole:8080/admin/

    - To finish, update moOde database for moOde 6.4:
Code:
sudo sqlite3 "/var/local/www/db/moode-sqlite3.db" "DROP TRIGGER IF EXISTS ro_columns"
sudo sqlite3 "/var/local/www/db/moode-sqlite3.db" "UPDATE cfg_hash SET ACTION = 'warning' WHERE PARAM = '/etc/nginx/nginx.conf'"


\\ ONLY FOR 6.4.1 - START
    - Update moOde database for moOde 6.4.1:
Code:
sudo sqlite3 "/var/local/www/db/moode-sqlite3.db" "DROP TRIGGER IF EXISTS ro_columns"
sudo sqlite3 "/var/local/www/db/moode-sqlite3.db" "UPDATE cfg_hash SET ACTION = 'warning' WHERE PARAM = '/etc/nginx/nginx.conf'"
sudo sqlite3 "/var/local/www/db/moode-sqlite3.db" "CREATE TRIGGER ro_columns BEFORE UPDATE OF param, value, [action] ON cfg_hash FOR EACH ROW BEGIN SELECT RAISE(ABORT, 'read only'); END;"

Code:
sudo nano -l /var/www/inc/playerlib.php

Comment lines 217, 218, 219, 220
Code:
//if ($row['id'] < 8 && $row['action'] !== 'exit') {
//      $_SESSION['ic_return_code'] = '2'; 
//      return false; 
//}
\\ ONLY FOR 6.4.1 - END

    - Reboot.

Hi TokeaFace,

does it work for version 6.2.1 ?

thanks Jempie


RE: moOde and Pi-Hole on Nginx - TookaFace - 06-19-2020

Hey,

Yes it work for 6.2.1, just the lines number in /var/www/inc/playerlib.php file are maybe not the same.


RE: moOde and Pi-Hole on Nginx - TookaFace - 08-19-2020

I've just update the procedure for moode version 6.4 and higher


RE: moOde and Pi-Hole on Nginx - LowkeyFlex - 01-14-2021

Awesome, I gonna try that in the near future! Does it also work for 7.0.1?


RE: moOde and Pi-Hole on Nginx - TookaFace - 01-14-2021

Yes, im using it with 7.0.1


RE: moOde and Pi-Hole on Nginx - Prince - 01-14-2021

Has the setup of pi-hole been changed?
The answer to install the webserver should be yes. Otherwise there will be no pihole-files in /var/www/. The answer for "Do you wish to install the web server (lighttpd) and required PHP modules?" should be no.


RE: moOde and Pi-Hole on Nginx - TookaFace - 01-14-2021

I've updated the procedure, thx


RE: moOde and Pi-Hole on Nginx - felichas - 02-21-2021

Hi,
Installing pi-hole works fine for me, but breaks Moode Audio.

I was running moode v6.7.1. Followed instructions and ended with a working pi-hole and a broken moode.
I didn't investigate much, to be hones, because I had to update to moode v7.0.1.
I have flashed my RPi Zero with HiFiBerry DAC and upgraded to v7.0.1. moode worked great again.
I have followed this intructions again... and moode is now broken, just like v6.7.1 was.

Configuration pages System, Network and Audio seem to work.
But the configuration page for the Library is now broken
This is the error I get:
Code:
lib-config: Connection to MPD failed

But most importantly, the main player is broken

I see the same error in /var/log/moode.log
Code:
20210221 223036 lib-config: Connection to MPD failed
20210221 223036 moode.php: MPD connect failed: cmd=(playlist)
20210221 223040 moode.php: MPD connect failed: cmd=(playlist)
20210221 223044 moode.php: MPD connect failed: cmd=(lsinfo)
20210221 223044 moode.php: MPD connect failed: cmd=(loadlib)

And no errors in /var/log/php_errors.log


Any advice on how to fix this? I like the idea of having both services in the same device.


RE: moOde and Pi-Hole on Nginx - TookaFace - 02-22-2021

It probably means the database uptade procedure has fail somehow.
So i suggest you to run again those 3 commands and reboot:
Code:
sudo sqlite3 "/var/local/www/db/moode-sqlite3.db" "DROP TRIGGER IF EXISTS ro_columns"
sudo sqlite3 "/var/local/www/db/moode-sqlite3.db" "UPDATE cfg_hash SET VALUE = '$(md5sum  /etc/nginx/nginx.conf | cut -d " " -f1)' WHERE PARAM = '/etc/nginx/nginx.conf'"
sudo sqlite3 "/var/local/www/db/moode-sqlite3.db" "CREATE TRIGGER ro_columns BEFORE UPDATE OF param, value, [action] ON cfg_hash FOR EACH ROW BEGIN SELECT RAISE(ABORT, 'read only'); END;"

I would need the full moode log to be sure.