Error during LibreNMS Install.php step 2: Could not connect to database, check logs/librenms.log

Installed LibreNMS on a new CentOS 7 fully patched box using https://docs.librenms.org/Installation/Installation-CentOS-7-Apache/.

Confirmed that mysql -u librenms -p librenms worked fine.

http:///Install.php:

  • intro screen: all 3 items are green
  • db login screen: errors if i put the wrong pwd in, but permits me to move to step 2 when i put the right pwd in.
  • step 2 screen: Could not connect to database, check logs/librenms.log

This same install procedure worked flawlessly about 10 days ago on a similar fresh build CentOS 7 box. (I’m installing on a new box to get distributed pollers).

Thanks in advance.

I found a workaround from https://docs.librenms.org/General/Updating/, but not a fix for the problem:

cd /iot/librenms
cp config.php.default config.php
vi config.php
set correct db username and password
git pull ; LOTS of files downloaded
composer install --no-dev
./build-base.php
php adduser.php NAME PWD 10 EMAIL
./validate.php

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

Component Version
LibreNMS 1.48.1-63-gae7e262
DB Schema 2019_01_16_195644_add_vrf_id_and_bgpLocalAs (131)
PHP 7.2.14
MySQL 5.5.60-MariaDB
RRDTool 1.4.8
SNMP NET-SNMP 5.7.2

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

[OK] Composer Version: 1.8.4
[OK] Dependencies up-to-date.
[OK] Database connection successful
[OK] Database schema correct
[WARN] You have not added any devices yet.
[FIX]:
You can add a device in the webui or with ./addhost.php
[FAIL] We have found some files that are owned by a different user than librenms, this will stop you updating automatically and / or rrd files being updated causing graphs to fail.
[FIX]:
sudo chown -R librenms:librenms /opt/librenms
sudo setfacl -d -m g::rwx /opt/librenms/rrd /opt/librenms/logs /opt/librenms/bootstrap/cache/ /opt/librenms/storage/
sudo chmod -R ug=rwX /opt/librenms/rrd /opt/librenms/logs /opt/librenms/bootstrap/cache/ /opt/librenms/storage/
Files:
/opt/librenms/.git/refs/heads/master
/opt/librenms/.git/index
/opt/librenms/.git/ORIG_HEAD
/opt/librenms/.github/label-actions.yml
/opt/librenms/LibreNMS/Alert/Transport/Alertmanager.php
/opt/librenms/LibreNMS/Alert/Transport/Canopsis.php
/opt/librenms/LibreNMS/Alert/Transport/Elasticsearch.php
/opt/librenms/LibreNMS/Alert/Transport/Mattermost.php
/opt/librenms/LibreNMS/Alert/Transport/Msteams.php
/opt/librenms/LibreNMS/Alert/Template.php
/opt/librenms/LibreNMS/Authentication/MysqlAuthorizer.php
/opt/librenms/LibreNMS/DB/Schema.php
/opt/librenms/LibreNMS/Interfaces/Alert/Transport.php
/opt/librenms/LibreNMS/OS/FsGbn.php
/opt/librenms/LibreNMS/OS/FsSwitch.php
and 5567 more…

I spoke too soon:

having run adduser USER PWD 10, i am unable to login to LibreNMS with those creds, but USER is listed in the librenms users table in mysql.

I’ve tried restarting mysql, httpd & the server, just to rule them out, but no change.

a simple “let’s add a distributed poller” has turned into a nightmare.

Was running into the same issues yesterday too and still haven’t gotten it working. I had an existing install that failed a few weeks ago that I’m trying to fix, but was just going to set up a fresh install for now (this one is just for my home network).

UPDATE: After yet another fresh install today, the behaviour is now different:

I followed https://docs.librenms.org/Installation/Installation-CentOS-7-Apache/ again, but this time i didn’t take a detour of installing the web server after the LibreNMS install (I’d tried with both Apache and NGINX on a previous install & had amended a copy of the instructions to defer the web installer & branch to either of the above).

This time i got “/var/lib/php/session not writeable” errror on the install.php title page. That was easily resolved by comparing with my working install from 10 days ago & chown root:apache /var/lib/php/session.

The rest of the GUI installer completed without a problem, then i was able to login to LibreNMS fine.

I ran daily.sh as the librenms user, but had to remove the following 2 files before the git merge would run:
storage/debugbar/.gitignore
storage/framework/cache/.gitignore
removing those files & re-running daily.sh did the trick.

Here’s the output of validate.php:

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

Component Version
LibreNMS 1.48.1-64-g9dba9f6
DB Schema 2019_01_16_195644_add_vrf_id_and_bgpLocalAs (131)
PHP 7.2.14
MySQL 5.5.60-MariaDB
RRDTool 1.4.8
SNMP NET-SNMP 5.7.2

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

[OK] Composer Version: 1.8.4
[OK] Dependencies up-to-date.
[OK] Database connection successful
[OK] Database schema correct
[WARN] You have not added any devices yet.
[FIX]:
You can add a device in the webui or with ./addhost.php
[WARN] Your local git contains modified files, this could prevent automatic updates.
[FIX]:
You can fix this with ./scripts/github-remove
Modified Files:
bootstrap/cache/.gitignore
logs/.gitignore
rrd/.gitignore
storage/app/.gitignore
storage/app/public/.gitignore
storage/framework/sessions/.gitignore
storage/framework/testing/.gitignore
storage/framework/views/.gitignore
storage/logs/.gitignore
[FAIL] Some folders have incorrect file permissions, this may cause issues.
[FIX]:
sudo chown -R librenms:librenms /opt/librenms
sudo setfacl -d -m g::rwx /opt/librenms/rrd /opt/librenms/logs /opt/librenms/bootstrap/cache/ /opt/librenms/storage/
sudo chmod -R ug=rwX /opt/librenms/rrd /opt/librenms/logs /opt/librenms/bootstrap/cache/ /opt/librenms/storage/
Files:
/opt/librenms/storage/framework/cache/.gitignore

The version number has moved on since i tried this yesterday.

The file system permissions are wrong again, despite me having previously run the fix commands (as the same problem was flagged in the GUI installer) and running daily.sh as the librenms user.

I don’t know if installing apache before of after LibreNMS makes a difference.
I don’t know why the /var/lib/php/session folder didn’t pick up the right permissions this time.

At this point, i need to run a couple more demo installs to confirm that the process is now more stable, then get back to configuring distributed pollers, which is why i was doing this second install.

Cache files are created by the webserver sometimes, which doesn’t run as the librenms user.

You can run ./scripts/github-remove -d to fix the .gitignore files.

Thanks, i did just that to fix them. If they would block future updates then they should be auto-cleared by the sinstaller / updater.

Any ideas why the installation behaviour issues arose?