Cacti (home)ForumsDocumentation
Cacti: offical forums and support
It is currently Sat May 25, 2019 2:09 pm

All times are UTC - 5 hours




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: FATAL: Connection to Cacti database failed.
PostPosted: Wed Jan 30, 2019 2:39 pm 
Offline

Joined: Wed Jan 30, 2019 2:14 pm
Posts: 9
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:
Quote:
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:
# 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:
# 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:
# 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:
$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:
# cat php.ini | grep mysql.default_socket
pdo_mysql.default_socket=
mysql.default_socket = /tmp/mysql.sock

Mysql works fine
Code:
# 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:
[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


Top
 Profile  
 
 Post subject: Re: FATAL: Connection to Cacti database failed.
PostPosted: Wed Jan 30, 2019 2:46 pm 
Offline
Cacti Guru User

Joined: Sun Aug 27, 2017 12:05 am
Posts: 2474
You have tried a mysql connection using the credentials in the config.php file? Also, do you have SELinux enabled?

_________________
Official Cacti Developer

Cacti Resources:
Cacti Website (including releases)
Cacti Issues
Cacti Development Releases
Cacti Development Documentation

My resources:
How to submit Pull Requests
Development Wiki and How To's
Updated NetSNMP Memory template for Cacti 1.x
Cisco SFP template for Cacti 0.8.8


Top
 Profile  
 
 Post subject: Re: FATAL: Connection to Cacti database failed.
PostPosted: Wed Jan 30, 2019 2:58 pm 
Offline

Joined: Wed Jan 30, 2019 2:14 pm
Posts: 9
What's SELinux?
I tried with config file connect, here:
Code:
% 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


Top
 Profile  
 
 Post subject: Re: FATAL: Connection to Cacti database failed.
PostPosted: Thu Jan 31, 2019 3:18 am 
Offline

Joined: Wed Jan 30, 2019 2:14 pm
Posts: 9
Create dbtest.php for test connection:
Code:
<?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:
# 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.


Top
 Profile  
 
 Post subject: Re: FATAL: Connection to Cacti database failed.
PostPosted: Thu Jan 31, 2019 3:29 am 
Offline
Cacti Guru User

Joined: Sun Aug 27, 2017 12:05 am
Posts: 2474
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:
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.

_________________
Official Cacti Developer

Cacti Resources:
Cacti Website (including releases)
Cacti Issues
Cacti Development Releases
Cacti Development Documentation

My resources:
How to submit Pull Requests
Development Wiki and How To's
Updated NetSNMP Memory template for Cacti 1.x
Cisco SFP template for Cacti 0.8.8


Top
 Profile  
 
 Post subject: Re: FATAL: Connection to Cacti database failed.
PostPosted: Thu Jan 31, 2019 3:49 am 
Offline

Joined: Wed Jan 30, 2019 2:14 pm
Posts: 9
My php.ini output:
Code:
# 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.


Top
 Profile  
 
 Post subject: Re: FATAL: Connection to Cacti database failed.
PostPosted: Thu Jan 31, 2019 4:50 am 
Offline

Joined: Wed Jan 30, 2019 2:14 pm
Posts: 9
I fixed config.php:
Code:
$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?


Top
 Profile  
 
 Post subject: Re: FATAL: Connection to Cacti database failed.
PostPosted: Thu Jan 31, 2019 9:46 am 
Offline

Joined: Wed Jan 30, 2019 2:14 pm
Posts: 9
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  

Protected by Anti-Spam ACP Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group