Unable to connect to database SQLSTATE[HY000] [1045] Access denied for user 'librenms'@'localhost' (using password: NO)

I followed the official guide to install librenms on my ubuntu 18 machine but am unable to access the install.php file

Output when I run ./validate.php as librenms user

====================================
Component | Version
--------- | -------
LibreNMS  | 22.1.0-69-g4c9d4eefd
DB Schema | Not Connected (0)
PHP       | 7.4.27
Python    | 3.6.9
MySQL     | ?
RRDTool   | 1.7.0
SNMP      | 5.7.3
====================================

[OK]    Composer Version: 2.2.6
[OK]    Dependencies up-to-date.
Could not connect to database, check logs/librenms.log.

Output when I run show grants for 'librenms'@'localhost';

+-----------------------------------------------------------------------------------------------------------------+
| Grants for librenms@localhost                                                                                   |
+-----------------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'librenms'@'localhost' IDENTIFIED BY PASSWORD '*2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19' |
| GRANT ALL PRIVILEGES ON `librenms`.* TO 'librenms'@'localhost'                                                  |
+-----------------------------------------------------------------------------------------------------------------+

My .env file contents

APP_KEY=base64:ip0Na/bjFysg8SbHrIly6j/Z0C0VfDgYKmWb/pmLm+0=

#DB_HOST=
#DB_DATABASE=
#DB_USERNAME=
#DB_PASSWORD=

#APP_URL=
INSTALL=true
NODE_ID=6209d6d6d3496
VAPID_PUBLIC_KEY=BLkdu9Y3l7I6f9dLYaR2xqlmjuS7BRx_KyVKnW3Tcgatm5HCunZSYIY6wfcwld7-HrTNLnKpC8E5MfIX8dDfmh4
VAPID_PRIVATE_KEY=OCNl6CT9hK2j3yISomgZ1AzdAmzsEKv0xCdU2_hnrfU

My /opt/librenms contents

addhost.php            bootstrap           composer.phar       daily.sh              html                   licenses     package.json                      phpunit.xml        requirements.txt  services-wrapper.py  tailwind.config.js
adduser.php            cache               config              database              includes               LICENSE.txt  package-lock.json                 ping.php           resources         snmpd.conf.example   tests
alerts.php             CHANGELOG.md        config.php.default  delhost.php           irc.php                lnms         pbin.sh                           poll-billing.php   routes            snmp-scan.py         validate.php
app                    check-services.php  config_to_json.php  discovery.php         LibreNMS               logs         phpstan-baseline-deprecated.neon  poller.php         rrd               snmptrap.php         vendor
artisan                CODE_OF_CONDUCT.md  CONTRIBUTING.md     discovery-wrapper.py  librenms.cron          mibs         phpstan-baseline.neon             poller-wrapper.py  scripts           sql-schema           webpack.mix.js
AUTHORS.md             composer.json       cronic              dist-pollers.php      librenms.nonroot.cron  misc         phpstan-deprecated.neon           README.md          SECURITY.md       storage
billing-calculate.php  composer.lock       daily.php           doc                   librenms-service.py    mkdocs.yml   phpstan.neon                      renamehost.php     server.php        syslog.php

Most recent log from /opt/librenms/log/librenms.log

Next Illuminate\Database\QueryException: SQLSTATE[HY000] [1045] Access denied for user 'librenms'@'localhost' (using password: NO) (SQL: select * from `config` where (`config_name` = snmp.unescape) limit 1) in /opt/librenms/vendor/laravel/framework/src/Illuminate/Database/Connection.php:712
Stack trace:
#0 /opt/librenms/vendor/laravel/framework/src/Illuminate/Database/Connection.php(672): Illuminate\Database\Connection->runQueryCallback()
#1 /opt/librenms/vendor/laravel/framework/src/Illuminate/Database/Connection.php(376): Illuminate\Database\Connection->run()
#2 /opt/librenms/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php(2385): Illuminate\Database\Connection->select()
#3 /opt/librenms/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php(2373): Illuminate\Database\Query\Builder->runSelect()
#4 /opt/librenms/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php(2907): Illuminate\Database\Query\Builder->Illuminate\Database\Query\{closure}()
#5 /opt/librenms/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php(2374): Illuminate\Database\Query\Builder->onceWithColumns()
#6 /opt/librenms/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php(625): Illuminate\Database\Query\Builder->get()
#7 /opt/librenms/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php(609): Illuminate\Database\Eloquent\Builder->getModels()
#8 /opt/librenms/vendor/laravel/framework/src/Illuminate/Database/Concerns/BuildsQueries.php(294): Illuminate\Database\Eloquent\Builder->get()
#9 /opt/librenms/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php(474): Illuminate\Database\Eloquent\Builder->first()
#10 /opt/librenms/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php(508): Illuminate\Database\Eloquent\Builder->firstOrNew()
#11 /opt/librenms/vendor/laravel/framework/src/Illuminate/Support/Traits/ForwardsCalls.php(23): Illuminate\Database\Eloquent\Builder->updateOrCreate()
#12 /opt/librenms/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php(2132): Illuminate\Database\Eloquent\Model->forwardCallTo()
#13 /opt/librenms/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php(2144): Illuminate\Database\Eloquent\Model->__call()
#14 /opt/librenms/LibreNMS/Config.php(256): Illuminate\Database\Eloquent\Model::__callStatic()
#15 /opt/librenms/LibreNMS/Config.php(478): LibreNMS\Config::persist()
#16 /opt/librenms/LibreNMS/Config.php(61): LibreNMS\Config::processConfig()
#17 /opt/librenms/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(967): LibreNMS\Config::load()
#18 /opt/librenms/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(910): Illuminate\Foundation\Application->fireAppCallbacks()
#19 /opt/librenms/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/BootProviders.php(17): Illuminate\Foundation\Application->boot()
#20 /opt/librenms/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(237): Illuminate\Foundation\Bootstrap\BootProviders->bootstrap()
#21 /opt/librenms/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(310): Illuminate\Foundation\Application->bootstrapWith()
#22 /opt/librenms/LibreNMS/Util/Laravel.php(44): Illuminate\Foundation\Console\Kernel->bootstrap()
#23 /opt/librenms/includes/init.php(88): LibreNMS\Util\Laravel::bootCli()
#24 /opt/librenms/config_to_json.php(13): require('/opt/librenms/i...')
#25 {main}

you need to as librenms user change into the directory you install Librenms in and:

sudo vi ./config.php

And add the following entries that should be similar to below:

#Database config
$config[‘db_host’] = ‘localhost’;
$config[‘db_port’] = ‘3306’;
$config[‘db_user’] = ‘librenms’;
$config[‘db_pass’] = ‘yourdbpassword’;
$config[‘db_name’] = ‘librenms’;
$config[‘db_socket’] = ‘’;

No, you need to modify the .env file, follow the offical guide instead, Installing LibreNMS - LibreNMS Docs

@Jellyfrog The official guide doesn’t mention changing the .env file anywhere. Could you please mention what modifications need to be made in the file exactly?

@Jellyfrog which portion of the documentation are you directing me to?

@Jellyfrog any updates?

The docs are not super clear (pull request welcome), but;

Final steps

That’s it! You now should be able to log in to http://librenms.example.com/

you need to do that, it will then setup your database, and configure the .env file

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.