Stuck installing on Debian 10: 502 Bad Gateway error when trying to get to install.php

Hi, i am new (to NGINX in particular) but i got stuck while I followed the https://docs.librenms.org/Installation/Install-LibreNMS/ procedures, and got the Error 502 at the stage of browsing to [server_address]/install.php.

Debian 10.5 Buster + Buster_backports.

the validate script says

> librenms@nooty:~$ ./validate.php
> d====================================
> Component | Version
> --------- | -------
> LibreNMS  | 1.66-43-g94fae616a
> DB Schema | Not Connected (0)
> PHP       | 7.3.19-1~deb10u1
> Python    | 3.7.3
> MySQL     | ?
> RRDTool   | 1.7.1
> SNMP      | NET-SNMP 5.7.3
> ====================================
> 
> [OK]    Composer Version: 1.10.10
> [OK]    Dependencies up-to-date.
> Could not connect to database, check logs/librenms.log.

I tried

What am I doing wrong?

replying to myself : if looking for answers, make sure that socket locations are the same… the default in docs /run/php-fpm-librenms.sock did not seem to work then I tried looking for answers and modified it ONLY in one place… I think i’m on track with this now.

I run on Deb with Nginx and I wasn’t really familiar with either of them before installing LibreNMS. I didn’t have to do anything really quirky with nginx configuration to get it to work. I’m reviewing the install information to see if I can make any sense of where this broke down for you –

The error sounds like it’s pretty obvious and should be a simple fix. LibreNMS can’t find the database. Did you verify mariadb is running? sudo systemctl status mariadb:

Status: “Taking your SQL requests now…”

Perhaps it’s a stupid question but have you verified that your librenms database exists with appropriate rights?

mysql -u root
MariaDB [(none)]> SHOW DATABASES;
MariaDB [(none)]> SHOW DATABASES;
±-------------------+
| Database |
±-------------------+
| information_schema |
| librenms |
| mysql |
| performance_schema |
±-------------------+
4 rows in set (0.090 sec)

verify that you have the librenms user:

SELECT user FROM mysql. user;
MariaDB [(none)]> SELECT user FROM mysql. user;
±---------+
| user |
±---------+
| fred |
| librenms |
| root |
±---------+

Double check permissions to the database for user librenms. I don’t know how to “check” but as far as I know there’s no harm in simply re-running the command to ensure the rights are there:

GRANT ALL PRIVILEGES ON librenms.* TO 'librenms'@'localhost';
FLUSH PRIVILEGES;

If that doesn’t make a difference did you enable a firewall? Maybe your vmware template for Debian has a firewall enabled that is blocking the connection? Finally, I’d worry a little about your nginx config now if you were tweaking on it.

Hi thank you for chiming in,

Got this OK

yes.

default debian (well, the ‘+backports’ from minimal ‘netinstall’ dvd image). So no firewall by default.

I have, but I did it at first as the docs said -
(https://docs.librenms.org/Installation/Install-LibreNMS/) - it ended with ‘502 Bad Gateway’ error when i went to ‘install.php’ stage;

then I googled and tried doing it more ‘debian’ way
(https://computingforgeeks.com/install-and-configure-librenms-on-debian-with-nginx/) whence at least one discrepancy came from (the docs have /run/ path to socket, the other instructions way has /var/run path to socket;)

then I tried making it good either way (/var/run in both php-fpm and nginx config, then /run in both) and still it did not help - other than changing from ‘file not found’ to permission denied’ in the error.log;

(that above suggestion came from Unable to continue fresh install - http://SERVER_IP/install.php giving 502 Bad Gateway - #4 by Barton)

And as of now, it’s still not working…
the

/var/log/nginx/error.log

says
connect() to unix:/run/php/php7.3-fpm-librenms.sock failed (13: Permission denied)…

And of course the 502 error still persists…

Which permissions is it missing and what should they be?

Personally I never encountered anything unusual when I installed. Used a debian template I made for VMWare, just base and followed the instructions. I don’t recall ever having to tweak anything with PHP or anything unusual with nginx.

From what little I gather about the bad gateway issue, it’s PHP related. If you create a PHP info page:
https://mediatemple.net/community/products/dv/204643880/how-can-i-create-a-phpinfo.php-page

and drop that in a web directory (like /var/www/html) can you browse to http://yourserver/phpinfo.php?

Also I’ll look at my files and see if I can get you some information about what I have on my php7.3-fpm-librenms.sock file.

here’s the permissions / ownership on this file:

root@librenms:/run/php# ls -l
total 4
-rw-r–r-- 1 root root 3 Aug 5 15:16 php7.3-fpm.pid
srw-rw---- 1 www-data www-data 0 Aug 5 15:16 php7.3-fpm.sock

I honestly don’t remember having to do anything with this…so it kind of looks like maybe something got FUBAR’d during some step of the install.

edit: additionally here’s my nginx config

server {
listen 80;
server_name librenms.mydomain.com;
root /opt/librenms/html;
index index.php;

charset utf-8;
gzip on;
gzip_types text/css application/javascript text/javascript application/x-javascript image/svg+xml text/plain text/xsd text/xsl text/xml i$
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location /api/v0 {
try_files $uri $uri/ /api_v0.php?$query_string;
}
location ~ .php {
include fastcgi.conf;
fastcgi_split_path_info ^(.+.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
}
location ~ /.ht {
deny all;
}
}

I don’t remember ever putting that configuration line into nginx. I’ll have to review the install instructions to see how it lands there

edit again: it’s this section in configuration instructions:

Configure PHP-FPM

> cp /etc/php/7.3/fpm/pool.d/www.conf /etc/php/7.3/fpm/pool.d/librenms.conf
> vi /etc/php/7.3/fpm/pool.d/librenms.conf
> ```
> 
> ```
> # Change "www" to "librenms"
> [librenms]
> 
> # Change user and group to "librenms"
> user = librenms
> group = librenms
> 
> # Change listen to a unique name
> listen = /run/php-fpm-librenms.sock
> ```

My permissions seem to be reading

root@nooty:/var/run/php# ls -l
total 4
-rw-r--r-- 1 root     root     5 Aug 28 16:18 php7.3-fpm.pid
srw-rw---- 1 librenms librenms 0 Aug 28 16:18 php7.3-fpm.sock

these are created when the php7.4-fpm service is running. so …
i got back into /etc/php/7.3/fpm/pool.d/librenms.conf and turned listen-owner and listen-data back to www-data…
and i seem to be getting somewhere now :slight_smile: (connecting by IP /install.php, it shows more steps - bacck in a bit :slight_smile:

in my case I tail de /var/log/nginx/error.log and I got the exact directory I had to copy /etc/php/7.4/fpm/pool.d/librenms.conf