502 Bad Gateway nginx/1.23.2

Hi there,

Since i updated to php8.1 i keep getting a 502 Bad Gateway message. I have been searching for a answer to the problem since 3 days and i am stil getting the same error, no matter which browser i use.
I have tried Edge, Firefox, Chrome and even Opera.
If i ran ./validate.php or ./daily.sh there seems to be no errors (beside the inactive node librenms)
I tried everything i could find on the internet, I even reinstalled php8.1, but nothing seems to work.
Can somebody help me, i am getting desperate being incapable solving this problem.

The output of ./validate.php is

Component Version
LibreNMS 22.11.0-4-gfb3c2ecb1 (2022-11-28T15:54:00+01:00)
DB Schema 2022_08_15_084507_add_rrd_type_to_wireless_sensors_table (248)
PHP 8.1.13
Python 3.10.6
Database MariaDB 10.6.11-MariaDB-0ubuntu0.22.04.1
RRDTool 1.7.2
SNMP 5.9.1

===========================================

[OK] Composer Version: 2.4.4
[OK] Dependencies up-to-date.
[OK] Database connection successful
[OK] Database Schema is current
[OK] SQL Server meets minimum requirements
[OK] lower_case_table_names is enabled
[OK] MySQL engine is optimal
[OK]
[OK] Database schema correct
[OK] MySQl and PHP time match
[OK] Active pollers found
[OK] Dispatcher Service has been used, but not recently
[OK] Locks are functional
[FAIL] Some poller nodes have not checked in recently
Inactive Nodes:
librenms
[OK] Redis is unavailable
[OK] rrdtool version ok
[OK] Connected to rrdcached

The output of ./daily.sh is
[email protected]:/opt/librenms$ ./daily.sh
Updating to latest codebase OK
Updating Composer packages OK
Updating SQL-Schema OK
Updating submodules OK
Cleaning up DB OK
Fetching notifications OK
Caching PeeringDB data OK
Caching Mac OUI data OK

Might be php-fpm still on the older version. Check in your librenms.log file, access_log, error_log etc.

Can try following through the installation doco closely to ensure it’s correct, or as a quick hack, try:

cp /etc/php/7.4/fpm/pool.d/librenms.conf /etc/php/8.1/fpm/pool.d/librenms.conf
systemctl restart php8.1-fpm

I tried the quick hack, but still the same.
Then i searched for errors and i found this error in /var/log/nginx/error.log:

2022/11/30 14:48:40 [crit] 1287#1287: *1 connect() to unix:/var/run/php/php-fpm.sock failed
(2: No such file or directory) while connecting to upstream, client: 192.168.151.240, server: ceclibrenms, request: “GET /dashboard/5 HTTP/1.1”, upstream: “fastcgi://unix:/var/run/php/php-fpm.sock:”, host: “192.168.100.101”

The strange thing is that the file php-fpm.sock was gone in var/run/php/php-fpm.sock. I am sure that this file or php8.1-fpm.sock was there before and dissapered suddenly. Is there a reason this file is simply gone?

I found the solution for this problem.
In /etc/php/8.1/fpm/pool.d/librenms.conf i changed the line: listen = /run/php/php8.1-fpm-librenms.sock to
listen = /run/php-fpm-librenms.sock . I tried this because the file php8.1-fpm-librenms.sock did not exist.
In /etc/nginx/conf.d/librenms.conf i changed the line line in strong textfastcgi_pass unix:/run/php-fpm-librenms.sock;
In /opt/librenms/composer.json i changed line 17 from “php”: “^7.4” to “php”: “^8.1”

I rebooted the server and than it worked!

Stil there was an issue with .daily.sh.
Here is the output:

[email protected]:/opt/librenms$ ./daily.sh
PHP Fatal error: Uncaught TypeError: array_diff(): Argument #1 ($array) must be of type array, null given in /opt/librenms/config.php:172
Stack trace:
#0 /opt/librenms/config.php(172): array_diff()
#1 Command line code(1): include(’…’)
#2 {main}
thrown in /opt/librenms/config.php on line 172
Updating to latest codebase ./daily.sh: line 62: /daily.log: Permission denied
./daily.sh: line 65: /daily.log: Permission denied
./daily.sh: line 66: /daily.log: Permission denied
OK
PHP Fatal error: Uncaught TypeError: array_diff(): Argument #1 ($array) must be of type array, null given in /opt/librenms/config.php:172
Stack trace:
#0 /opt/librenms/config.php(172): array_diff()
#1 Command line code(1): include(’…’)
#2 {main}
thrown in /opt/librenms/config.php on line 172
Updating Composer packages /opt/librenms/daily.sh: line 62: /daily.log: Permission denied
/opt/librenms/daily.sh: line 65: /daily.log: Permission denied
/opt/librenms/daily.sh: line 66: /daily.log: Permission denied
FAIL

LibreNMS\ComposerHelper::preInstall
Installing dependencies from lock file
Verifying lock file contents can be installed on current platform.
Nothing to install, update or remove
Package swiftmailer/swiftmailer is abandoned, you should avoid using it. Use symfony/mailer instead.
Package php-cs-fixer/diff is abandoned, you should avoid using it. No replacement was suggested.
Generating optimized autoload files
Illuminate\Foundation\ComposerScripts::postAutoloadDump
@php artisan package:discover --ansi
Discovered Package: fruitcake/laravel-cors
Discovered Package: laravel-notification-channels/webpush
Discovered Package: laravel/socialite
Discovered Package: laravel/tinker
Discovered Package: laravel/ui
Discovered Package: librenms/laravel-vue-i18n-generator
Discovered Package: mews/purifier
Discovered Package: nesbot/carbon
Discovered Package: php-flasher/flasher-laravel
Discovered Package: tightenco/ziggy
Package manifest generated successfully.
66 packages you are using are looking for funding.
Use the composer fund command to find out more!
LibreNMS\ComposerHelper::postInstall

In config.php line 172:

[TypeError]
array_diff(): Argument #1 ($array) must be of type array, null given

Exception trace:
at /opt/librenms/config.php:172
array_diff() at /opt/librenms/config.php:172
include() at /opt/librenms/LibreNMS/ComposerHelper.php:135
LibreNMS\ComposerHelper::populateEnv() at /opt/librenms/LibreNMS/ComposerHelper.php:49
LibreNMS\ComposerHelper::postInstall() at phar:///opt/librenms/composer.phar/src/Composer/EventDispatcher/EventDispatcher.php:386
Composer\EventDispatcher\EventDispatcher->executeEventPhpScript() at phar:///opt/librenms/composer.phar/src/Composer/EventDispatcher/EventDispatcher.php:246
Composer\EventDispatcher\EventDispatcher->doDispatch() at phar:///opt/librenms/composer.phar/src/Composer/EventDispatcher/EventDispatcher.php:123
Composer\EventDispatcher\EventDispatcher->dispatchScript() at phar:///opt/librenms/composer.phar/src/Composer/Installer.php:374
Composer\Installer->run() at phar:///opt/librenms/composer.phar/src/Composer/Command/InstallCommand.php:144
Composer\Command\InstallCommand->execute() at phar:///opt/librenms/composer.phar/vendor/symfony/console/Command/Command.php:298
Symfony\Component\Console\Command\Command->run() at phar:///opt/librenms/composer.phar/vendor/symfony/console/Application.php:1028
Symfony\Component\Console\Application->doRunCommand() at phar:///opt/librenms/composer.phar/vendor/symfony/console/Application.php:299
Symfony\Component\Console\Application->doRun() at phar:///opt/librenms/composer.phar/src/Composer/Console/Application.php:375
Composer\Console\Application->doRun() at phar:///opt/librenms/composer.phar/vendor/symfony/console/Application.php:171
Symfony\Component\Console\Application->run() at phar:///opt/librenms/composer.phar/src/Composer/Console/Application.php:139
Composer\Console\Application->run() at phar:///opt/librenms/composer.phar/bin/composer:88
require() at /opt/librenms/composer.phar:29

install [–prefer-source] [–prefer-dist] [–prefer-install PREFER-INSTALL] [–dry-run] [–dev] [–no-suggest] [–no-dev] [–no-autoloader] [–no-progress] [–no-install] [–audit] [–audit-format AUDIT-FORMAT] [-v|vv|vvv|–verbose] [-o|–optimize-autoloader] [-a|–classmap-authoritative] [–apcu-autoloader] [–apcu-autoloader-prefix APCU-AUTOLOADER-PREFIX] [–ignore-platform-req IGNORE-PLATFORM-REQ] [–ignore-platform-reqs] [–] […]
Updating SQL-Schema /opt/librenms/daily.sh: line 62: /daily.log: Permission denied
/opt/librenms/daily.sh: line 65: /daily.log: Permission denied
/opt/librenms/daily.sh: line 66: /daily.log: Permission denied
OK
Updating submodules /opt/librenms/daily.sh: line 62: /daily.log: Permission denied
/opt/librenms/daily.sh: line 65: /daily.log: Permission denied
/opt/librenms/daily.sh: line 66: /daily.log: Permission denied
OK
Cleaning up DB /opt/librenms/daily.sh: line 62: /daily.log: Permission denied
/opt/librenms/daily.sh: line 65: /daily.log: Permission denied
/opt/librenms/daily.sh: line 66: /daily.log: Permission denied
OK
Fetching notifications /opt/librenms/daily.sh: line 62: /daily.log: Permission denied
/opt/librenms/daily.sh: line 65: /daily.log: Permission denied
/opt/librenms/daily.sh: line 66: /daily.log: Permission denied
OK
Caching PeeringDB data /opt/librenms/daily.sh: line 62: /daily.log: Permission denied
/opt/librenms/daily.sh: line 65: /daily.log: Permission denied
/opt/librenms/daily.sh: line 66: /daily.log: Permission denied
OK
Caching Mac OUI data /opt/librenms/daily.sh: line 62: /daily.log: Permission denied
/opt/librenms/daily.sh: line 65: /daily.log: Permission denied
/opt/librenms/daily.sh: line 66: /daily.log: Permission denied
OK

I blocked line 172 in /opt/librenms/config.php and the the output of ./daily.sh was:

Updating to latest codebase OK
Updating Composer packages OK
Updated from 2a8b8b864 to 0ef39344f OK
Updating SQL-Schema OK
Updating submodules OK
Cleaning up DB OK
Fetching notifications OK
Caching PeeringDB data OK
Caching Mac OUI data OK

Updating to latest codebase OK
Updating Composer packages OK
Updated from 2a8b8b864 to 0ef39344f OK
Updating SQL-Schema OK
Updating submodules OK
Cleaning up DB OK
Fetching notifications OK
Caching PeeringDB data OK
Caching Mac OUI data OK