PHP8.1 Upgrade Undefined Constant 'localhost;

Hi - I have just upgraded our Ubuntu server from 20.04 to 22.04 and am having some troubles getting it to work.

I have done the below:
sudo apt-get update
sudo apt-get upgrade -y
sudo apt-get dist-upgrade
sudo do-release-upgrade

It then rebooted into the new version. I then ran:
apt install acl curl fping git graphviz imagemagick mariadb-client mariadb-server mtr-tiny nginx-full nmap php-cli php-curl php-fpm php-gd php-gmp php-json php-mbstring php-mysql php-snmp php-xml php-zip rrdtool snmp snmpd whois unzip python3-pymysql python3-dotenv python3-redis python3-setuptools python3-systemd python3-pip

and then set the time in the php.ini files of version 8.1

I am getting this in the logs:
[2022-10-27T15:50:01.523754+01:00] production.ERROR: Undefined constant “localhost” {“exception”:"[object] (Error(code: 0): Undefined constant “localhost” at /data/librenms/config.php:86)"}

(/data is just a symbolic link to /opt/librenms)

I have checked and I have an entry in my php.ini file with that entry at line 86:

$config[‘db_host’] = localhost;

validata.php output below:

librenms@gspplibrenms02:~$ ./validate.php

In config.php line 86:

Undefined constant “localhost”

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

Component Version
LibreNMS 22.9.0-3-g06c361c2b
DB Schema Not Connected (0)
PHP 8.1.2-1ubuntu2.6
Python 3.10.6
Database Not Connected
RRDTool 1.7.2
SNMP 5.9.1

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

[OK] Composer Version: 2.4.3
[OK] Dependencies up-to-date.

Not quite sure how to get around this error message as it is set the same as the older version which worked. Appreciate any thoughts please?

Cheers

Have you tried:

cd /opt/librenms
git pull
./scripts/composer_wrapper.php install --no-dev
php includes/sql-schema/update.php
./validate.php

If I run the git pull then this will override all of the files in that directory including the RRD files and config.php. This would mean having to restore data to get it working again. I was hoping to do this more as an upgrade like done in PHP upgrade 7.4.3 to 8.1 - #5 by murrant by Murrant.
If I run the composer_wrapper I still get messages about the Undefined constant “localhost” I am wondering if there are any changes in the way PHP reads this between 7 and 8?
$config[‘db_host’] = localhost;
$config[‘db_name’] = librenms;
$config[‘db_user’] = *******;
$config[‘db_pass’] = ******;

I ask you that because it is also in the update documentation:

Updating - LibreNMS Docs

Just to be sure you have last version of all files…

Thanks, I have just tried to run git pull and it is actually responding that it is up to date:
librenms@*********:~$ git pull
remote: Enumerating objects: 6, done.
remote: Counting objects: 100% (6/6), done.
remote: Compressing objects: 100% (6/6), done.
remote: Total 6 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (6/6), 25.25 KiB | 1.26 MiB/s, done.
From GitHub - librenms/librenms: Community-based GPL-licensed network monitoring system
0dd183f1e…b90fbcb9b master → origin/master
Already up-to-date.

change it to
$config[‘db_host’] = ‘localhost’;

Hi
That worked thanks, I also had to amend the entry in the .env file which contained the same details. Once I did that I can get to the login screen again.

Thanks for the input.

Better yet, delete all “db_*” variables from config.php, they don’t do anything :wink:

Yes, .env should be enough

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