FATAL: Connection to Cacti database failed.

Post support questions that directly relate to Linux/Unix operating systems.

Moderators: Moderators, Developers

Post Reply
Author
Message
vovas
Posts: 9
Joined: Wed Jan 30, 2019 2:14 pm
Contact:

FATAL: Connection to Cacti database failed.

#1 Post by vovas » Wed Jan 30, 2019 2:39 pm

Hi folks!

Again this trouble. Already read all topics here, but no one doesn't help

So, I've installed Cacti and write info to config file. After that I open browser and see that:
FATAL: Connection to Cacti database failed. Please ensure:

the PHP MySQL module is installed and enabled.
the database is running.
the credentials in config.php are valid.
PHP ini info:

Code: Select all

# php --ini
Configuration File (php.ini) Path: /usr/local/etc
Loaded Configuration File:         /usr/local/etc/php.ini
Scan for additional .ini files in: /usr/local/etc/php
Additional .ini files parsed:      /usr/local/etc/php/ext-18-session.ini,
/usr/local/etc/php/ext-20-bz2.ini,
/usr/local/etc/php/ext-20-ctype.ini,
/usr/local/etc/php/ext-20-filter.ini,
/usr/local/etc/php/ext-20-gd.ini,
/usr/local/etc/php/ext-20-gettext.ini,
/usr/local/etc/php/ext-20-gmp.ini,
/usr/local/etc/php/ext-20-hash.ini,
/usr/local/etc/php/ext-20-json.ini,
/usr/local/etc/php/ext-20-ldap.ini,
/usr/local/etc/php/ext-20-mbstring.ini,
/usr/local/etc/php/ext-20-mysqli.ini,
/usr/local/etc/php/ext-20-openssl.ini,
/usr/local/etc/php/ext-20-pdo.ini,
/usr/local/etc/php/ext-20-posix.ini,
/usr/local/etc/php/ext-20-simplexml.ini,
/usr/local/etc/php/ext-20-snmp.ini,
/usr/local/etc/php/ext-20-sockets.ini,
/usr/local/etc/php/ext-20-xml.ini,
/usr/local/etc/php/ext-20-zip.ini,
/usr/local/etc/php/ext-20-zlib.ini,
/usr/local/etc/php/ext-30-pdo_mysql.ini
PHP version

Code: Select all

# php -v
PHP 7.2.14 (cli) (built: Jan 30 2019 12:19:04) ( ZTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
PHP modules:

Code: Select all

# php -m
[PHP Modules]
bz2
Core
ctype
date
filter
gd
gettext
gmp
hash
json
ldap
libxml
mbstring
mysqli
mysqlnd
openssl
pcre
PDO
pdo_mysql
posix
Reflection
session
SimpleXML
snmp
sockets
SPL
standard
xml
zip
zlib

[Zend Modules]
Cacto config

Code: Select all

$database_type     = 'mysql';
$database_default  = 'cacti';
$database_hostname = 'localhost';
$database_username = 'cacti';
$database_password = 'cacti';
$database_port     = '/tmp/mysql.sock';
$database_ssl      = false;
$database_ssl_key  = '';
$database_ssl_cert = '';
$database_ssl_ca   = '';
Mysql socket on php.ini

Code: Select all

# cat php.ini | grep mysql.default_socket
pdo_mysql.default_socket=
mysql.default_socket = /tmp/mysql.sock
Mysql works fine

Code: Select all

# sockstat | grep mysql
mysql    mysqld     65019 67 stream /tmp/mysql.sock
mysql    mysqld     65019 69 stream /tmp/mysqlx.sock
mysql    mysqld     65019 70 stream /tmp/mysql.sock
www      httpd      63700 9  stream -> /tmp/mysql.sock
Connect to socket:

Code: Select all

[email protected]:~ % mysqladmin --protocol=SOCKET --socket=/tmp/mysql.sock -u root -p version
Enter password:
mysqladmin  Ver 8.0.14 for FreeBSD11.2 on amd64 (Source distribution)
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Server version          8.0.14
Protocol version        10
Connection              Localhost via UNIX socket
UNIX socket             /tmp/mysql.sock
Uptime:                 24 min 59 sec

Threads: 2  Questions: 3  Slow queries: 0  Opens: 110  Flush tables: 2  Open tables: 86  Queries per second avg: 0.002

netniV
Cacti Guru User
Posts: 2685
Joined: Sun Aug 27, 2017 12:05 am

Re: FATAL: Connection to Cacti database failed.

#2 Post by netniV » Wed Jan 30, 2019 2:46 pm

You have tried a mysql connection using the credentials in the config.php file? Also, do you have SELinux enabled?

vovas
Posts: 9
Joined: Wed Jan 30, 2019 2:14 pm
Contact:

Re: FATAL: Connection to Cacti database failed.

#3 Post by vovas » Wed Jan 30, 2019 2:58 pm

What's SELinux?
I tried with config file connect, here:

Code: Select all

% mysql -u cacti -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.14 Source distribution

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
If I open through browser, it doesn't work

vovas
Posts: 9
Joined: Wed Jan 30, 2019 2:14 pm
Contact:

Re: FATAL: Connection to Cacti database failed.

#4 Post by vovas » Thu Jan 31, 2019 3:18 am

Create dbtest.php for test connection:

Code: Select all

<?php
$link = mysqli_connect('localhost:/tmp/mysql.sock', 'cacti', 'cacti', 'cacti');

if (!$link) {
    echo "Error: Unable to connect to MySQL." . PHP_EOL;
    echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
    echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
    exit;
}

echo "Success: A proper connection to MySQL was made! The my_db database is great." . PHP_EOL;
echo "Host information: " . mysqli_get_host_info($link) . PHP_EOL;

mysqli_close($link);
?>
Output:

Code: Select all

# php dbtest.php
PHP Warning:  mysqli_connect(): (HY000/2002): Can't assign requested address in /usr/local/www/apache24/data/dbtest.php on line 2
Error: Unable to connect to MySQL.
Debugging errno: 2002
Debugging error: Can't assign requested address
Use mysqli_connect instead mysql_connection, because mysql_connection function is deprecated on mysql 8 version.
So, I may connect to mysql server from freebsd console, but can't connect through php script. May be problem with php.ini configuration? But phpmyadmin works fine.

netniV
Cacti Guru User
Posts: 2685
Joined: Sun Aug 27, 2017 12:05 am

Re: FATAL: Connection to Cacti database failed.

#5 Post by netniV » Thu Jan 31, 2019 3:29 am

OK, this is a CLI vs Web issue with the PHP.INI. You need to make sure you have all the required cacti modules enabled in both CLI and Web for PHP.

Code: Select all

php -i | grep "\.ini"
Configuration File (php.ini) Path => /etc/php/7.2/cli
Loaded Configuration File => /etc/php/7.2/cli/php.ini
Scan this dir for additional .ini files => /etc/php/7.2/cli/conf.d
Additional .ini files parsed => /etc/php/7.2/cli/conf.d/10-mysqlnd.ini,
/etc/php/7.2/cli/conf.d/10-opcache.ini,
/etc/php/7.2/cli/conf.d/10-pdo.ini,
/etc/php/7.2/cli/conf.d/15-xml.ini,
/etc/php/7.2/cli/conf.d/20-bcmath.ini,
/etc/php/7.2/cli/conf.d/20-calendar.ini,
/etc/php/7.2/cli/conf.d/20-ctype.ini,
/etc/php/7.2/cli/conf.d/20-curl.ini,
/etc/php/7.2/cli/conf.d/20-dom.ini,
/etc/php/7.2/cli/conf.d/20-exif.ini,
/etc/php/7.2/cli/conf.d/20-fileinfo.ini,
/etc/php/7.2/cli/conf.d/20-ftp.ini,
/etc/php/7.2/cli/conf.d/20-gd.ini,
/etc/php/7.2/cli/conf.d/20-gettext.ini,
/etc/php/7.2/cli/conf.d/20-gmp.ini,
/etc/php/7.2/cli/conf.d/20-iconv.ini,
/etc/php/7.2/cli/conf.d/20-json.ini,
/etc/php/7.2/cli/conf.d/20-ldap.ini,
/etc/php/7.2/cli/conf.d/20-mbstring.ini,
/etc/php/7.2/cli/conf.d/20-mysqli.ini,
/etc/php/7.2/cli/conf.d/20-pdo_mysql.ini,
/etc/php/7.2/cli/conf.d/20-phar.ini,
/etc/php/7.2/cli/conf.d/20-posix.ini,
/etc/php/7.2/cli/conf.d/20-readline.ini,
/etc/php/7.2/cli/conf.d/20-shmop.ini,
/etc/php/7.2/cli/conf.d/20-simplexml.ini,
/etc/php/7.2/cli/conf.d/20-snmp.ini,
/etc/php/7.2/cli/conf.d/20-sockets.ini,
/etc/php/7.2/cli/conf.d/20-sysvmsg.ini,
/etc/php/7.2/cli/conf.d/20-sysvsem.ini,
/etc/php/7.2/cli/conf.d/20-sysvshm.ini,
/etc/php/7.2/cli/conf.d/20-tokenizer.ini,
/etc/php/7.2/cli/conf.d/20-wddx.ini,
/etc/php/7.2/cli/conf.d/20-xmlreader.ini,
/etc/php/7.2/cli/conf.d/20-xmlwriter.ini,
/etc/php/7.2/cli/conf.d/20-xsl.ini
user_ini.filename => .user.ini => .user.ini
That is, for example, where the ubuntu stuff sits for 7.2 on the cli, but for the web it is in /etc/php/7.2/apache2/

This is also the reason that I introduced a bug fix in 1.2.1 to run a CLI check for PHP recommendations and modules within the web installer.

vovas
Posts: 9
Joined: Wed Jan 30, 2019 2:14 pm
Contact:

Re: FATAL: Connection to Cacti database failed.

#6 Post by vovas » Thu Jan 31, 2019 3:49 am

My php.ini output:

Code: Select all

# php -i | grep "\.ini"
Configuration File (php.ini) Path => /usr/local/etc
Loaded Configuration File => /usr/local/etc/php.ini
Scan this dir for additional .ini files => /usr/local/etc/php
Additional .ini files parsed => /usr/local/etc/php/ext-10-opcache.ini,
/usr/local/etc/php/ext-18-session.ini,
/usr/local/etc/php/ext-20-bcmath.ini,
/usr/local/etc/php/ext-20-bz2.ini,
/usr/local/etc/php/ext-20-ctype.ini,
/usr/local/etc/php/ext-20-dom.ini,
/usr/local/etc/php/ext-20-filter.ini,
/usr/local/etc/php/ext-20-ftp.ini,
/usr/local/etc/php/ext-20-gd.ini,
/usr/local/etc/php/ext-20-gettext.ini,
/usr/local/etc/php/ext-20-gmp.ini,
/usr/local/etc/php/ext-20-hash.ini,
/usr/local/etc/php/ext-20-iconv.ini,
/usr/local/etc/php/ext-20-json.ini,
/usr/local/etc/php/ext-20-ldap.ini,
/usr/local/etc/php/ext-20-mbstring.ini,
/usr/local/etc/php/ext-20-mysqli.ini,
/usr/local/etc/php/ext-20-openssl.ini,
/usr/local/etc/php/ext-20-pdo.ini,
/usr/local/etc/php/ext-20-posix.ini,
/usr/local/etc/php/ext-20-simplexml.ini,
/usr/local/etc/php/ext-20-snmp.ini,
/usr/local/etc/php/ext-20-soap.ini,
/usr/local/etc/php/ext-20-sockets.ini,
/usr/local/etc/php/ext-20-sqlite3.ini,
/usr/local/etc/php/ext-20-tokenizer.ini,
/usr/local/etc/php/ext-20-xml.ini,
/usr/local/etc/php/ext-20-xmlwriter.ini,
/usr/local/etc/php/ext-20-zip.ini,
/usr/local/etc/php/ext-20-zlib.ini,
/usr/local/etc/php/ext-30-pdo_mysql.ini,
/usr/local/etc/php/ext-30-pdo_sqlite.ini,
/usr/local/etc/php/ext-30-phar.ini,
/usr/local/etc/php/ext-30-xmlreader.ini,
/usr/local/etc/php/ext-30-xsl.ini
user_ini.filename => .user.ini => .user.ini
All required modules for Cacti are installed.

vovas
Posts: 9
Joined: Wed Jan 30, 2019 2:14 pm
Contact:

Re: FATAL: Connection to Cacti database failed.

#7 Post by vovas » Thu Jan 31, 2019 4:50 am

I fixed config.php:

Code: Select all

$database_type     = 'mysql';
$database_default  = 'cacti';
$database_hostname = 'localhost';
$database_username = 'cacti';
$database_password = 'cacti';
/*$database_port     = '/tmp/mysql.sock';*/
$database_ssl      = false;
$database_ssl_key  = '';
$database_ssl_cert = '';
$database_ssl_ca   = '';
Open browser and new error:
Image
Checked again mysql connection through console with cacti user, result ok.
DB created with all permission for cacti user. Why installer doesn't connect to db?

vovas
Posts: 9
Joined: Wed Jan 30, 2019 2:14 pm
Contact:

Re: FATAL: Connection to Cacti database failed.

#8 Post by vovas » Thu Jan 31, 2019 9:46 am

Final step: delete mysql 8 version. Too many errors with it.
Installed MariaDB 10.3 version. Import db and install script works fine with /tmp/mysql.sock

Post Reply