Cacti (home)ForumsDocumentation
Cacti: offical forums and support
It is currently Mon Oct 22, 2018 7:53 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 10 posts ] 
Author Message
 Post subject: FATAL: Cannot connect to MySQL server on 'localhost'
PostPosted: Thu Feb 08, 2018 7:28 pm 
Offline

Joined: Thu Feb 08, 2018 7:16 pm
Posts: 7
ENV: Linux Mint, 18.2, php 5.6/7.0 mysql Ver 14.14 Distrib 5.7.21, for Linux (x86_64) using EditLine wrapper

Greetings all. I have installed Cacti in the above environment but am unable to generate any graphs. After some debugging I find that poller.php is unable to populate the db, giving the error: FATAL: Cannot connect to MySQL server on 'localhost'. Please make sure you have specified a valid MySQL database name in 'include/config.php'. I have tried the following steps:

1. Verified grants/permissions of the cacti user in mysql by connecting using those credentials on cli.
2. Double checked the settings in config.php are correct.
3. Changed the driver from mysqli to mysql to verify the mysqli driver is being used (abo_mysql.inc.php actually doesn't exist)
4. Verified all permissions on the directories are set to www-data/www-data

I searched for this problem in previous posts, but didn't find any exactly like it. Any ideas? Thanks in advance for looking.


Top
 Profile  
 
 Post subject: Re: FATAL: Cannot connect to MySQL server on 'localhost'
PostPosted: Thu Feb 08, 2018 8:24 pm 
Offline
Cacti Guru User

Joined: Sun Aug 27, 2017 12:05 am
Posts: 1519
Are you seeing any PHP errors in the log files or any other warnings?

_________________
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: Cannot connect to MySQL server on 'localhost'
PostPosted: Fri Feb 09, 2018 6:27 am 
Offline

Joined: Thu Feb 08, 2018 7:16 pm
Posts: 7
No php errors, or any errors in /var/log/cacti/cacti, poller-error or rrd.log. The rest of the site works as expected.


Top
 Profile  
 
 Post subject: Re: FATAL: Cannot connect to MySQL server on 'localhost'
PostPosted: Fri Feb 09, 2018 8:27 am 
Offline
Cacti Guru User
User avatar

Joined: Thu Jan 31, 2008 6:39 am
Posts: 2695
Location: Kressbronn, Germany
PHP errors need to be enabled first, so go to your php.ini file and enable it by uncommenting

Code:
# error_log = syslog


to

Code:
error_log = syslog


Then restart the webserver and check your syslog for PHP errors.

Also check if se-linux is enabled which may prevent the Webserver to actually start any network connections ( to your database server )

_________________
Greetings,
Phalek
---
Need more help ? Read the Cacti documentation or my new Cacti 1.x Book
Need on-site support ? Look here Cacti Workshop
Need professional Cacti support ? Look here CereusService
---
Plugins : CereusTransporter | CereusReporting | nmidWebService | nmidSmokeping | nmidWeb2 |

Code:
CereusServer Master:  SYSTEM STATS: Time:2.5621 Method:spine Processes:1 Threads:16 Hosts:446 HostsPerProcess:446 DataSources:14683 RRDsProcessed:7573
CereusServer Agent:   SYSTEM STATS: Time:27.4840 Method:spine Processes:1 Threads:8 Hosts:16 HostsPerProcess:16 DataSources:114576 RRDsProcessed:48061


Top
 Profile  
 
 Post subject: Re: FATAL: Cannot connect to MySQL server on 'localhost'
PostPosted: Tue Feb 13, 2018 3:44 am 
Offline

Joined: Thu Feb 08, 2018 7:16 pm
Posts: 7
Thank you, I had already done that, and, no errors.


Top
 Profile  
 
 Post subject: Re: FATAL: Cannot connect to MySQL server on 'localhost'
PostPosted: Tue Feb 13, 2018 10:17 am 
Offline

Joined: Thu Feb 08, 2018 7:16 pm
Posts: 7
I installed from source, and got this: php poller.php
PHP Fatal error: Uncaught Error: Undefined class constant 'MYSQL_ATTR_FOUND_ROWS' in /usr/share/cacti/site/lib/database.php:53
Stack trace:
#0 /usr/share/cacti/site/include/global.php(215): db_connect_real('localhost', 'cacti', 'xxxxxxxx', 'cacti', 'mysql', '3306', false)
#1 /usr/share/cacti/site/poller.php(64): include('/usr/share/cact...')
#2 {main}
thrown in /usr/share/cacti/site/lib/database.php on line 53

php-cli: php --version
PHP 7.0.27-1+ubuntu16.04.1+deb.sury.org+1 (cli) (built: Jan 5 2018 14:12:46) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
with Zend OPcache v7.0.27-1+ubuntu16.04.1+deb.sury.org+1, Copyright (c) 1999-2017, by Zend Technologies
with Xdebug v2.6.0, Copyright (c) 2002-2018, by Derick Rethans


Top
 Profile  
 
 Post subject: Re: FATAL: Cannot connect to MySQL server on 'localhost'
PostPosted: Tue Feb 13, 2018 10:23 am 
Offline

Joined: Thu Feb 08, 2018 7:16 pm
Posts: 7
Having said that, doing:

Code:
php5.6 poller.php


and updating /etc/crontab with php5.6 seems to have solved this issue.


Top
 Profile  
 
 Post subject: Re: FATAL: Cannot connect to MySQL server on 'localhost'
PostPosted: Thu Feb 15, 2018 4:54 am 
Offline
Cacti Guru User

Joined: Sun Aug 27, 2017 12:05 am
Posts: 1519
I would check if you have any differences between what the mods and settings are for both php5.6 and php7.0. Any differences may be causing the issue. You may also want to check the differences between apache and cli too if only cli is giving you the issues.

_________________
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: Cannot connect to MySQL server on 'localhost'
PostPosted: Sun Feb 25, 2018 4:30 pm 
Offline

Joined: Thu Feb 08, 2018 7:16 pm
Posts: 7
My cacti instance was generating empty graphs. I noticed the "- q" option and also that cacti was using /usr/bin/php in the following log output:

Code:
2018-02-24 12:25:00 - POLLER: Poller[Main Poller] DEBUG: About to Spawn a Remote Process [CMD: /usr/bin/php, ARGS: -q "/var/www/html/cacti/cmd.php" --poller=1 --first=1 --last=1 --mibs]
2018-02-24 12:25:00 - POLLER: Poller[Main Poller] DEBUG: About to Spawn a Remote Process [CMD: /usr/bin/php, ARGS: -q "/var/www/html/cacti/cmd.php" --poller=1 --first=0 --last=0 --mibs]
2018-02-24 12:25:00 - POLLER: Poller[Main Poller] DEBUG: About to Spawn a Remote Process [CMD: /usr/bin/php, ARGS: -q /var/www/html/cacti/poller_maintenance.php]
2018-02-24 12:25:00 - POLLER: Poller[Main Poller] DEBUG: About to Spawn a Remote Process [CMD: /usr/bin/php, ARGS: -q /var/www/html/cacti/poller_automation.php -M]
2018-02-24 12:25:00 - POLLER: Poller[Main Poller] DEBUG: About to Spawn a Remote Process [CMD: /usr/bin/php, ARGS: -q /var/www/html/cacti/poller_spikekill.php]
2018-02-24 12:25:00 - POLLER: Poller[Main Poller] DEBUG: About to Spawn a Remote Process [CMD: /usr/bin/php, ARGS: -q /var/www/html/cacti/poller_reports.php]
2018-02-24 12:25:00 - POLLER: Poller[Main Poller] DEBUG: About to Spawn a Remote Process [CMD: /usr/bin/php, ARGS: -q /var/www/html/cacti/poller_boost.php]
2018-02-24 12:20:01 - POLLER: Poller[Main Poller] DEBUG: About to Spawn a Remote Process [CMD: /usr/bin/php, ARGS: -q "/var/www/html/cacti/cmd.php" --poller=1 --first=1 --last=1 --mibs]
2018-02-24 12:20:01 - POLLER: Poller[Main Poller] DEBUG: About to Spawn a Remote Process [CMD: /usr/bin/php, ARGS: -q "/var/www/html/cacti/cmd.php" --poller=1 --first=0 --last=0 --mibs]


So simply specifying the full path php5.6 in crontab didn't completely solve graphing issues. What follows shows how I updated cli using /etc/alternatives, and apache to use php5.6:

Apache:-
Code:
sudo a2dismod php7.1
sudo a2enmod php5.6
sudo service apache2 restart


Command Line:-
Code:
sudo update-alternatives --set php /usr/bin/php5.6
sudo update-alternatives --set phar /usr/bin/phar5.6
sudo update-alternatives --set phar.phar /usr/bin/phar.phar5.6
sudo update-alternatives --set phpize /usr/bin/phpize5.6
sudo update-alternatives --set php-config /usr/bin/php-config5.6


Ultimately, I also downloaded the latest version of cacti, 1.1.35 from cacti.net, and untared in into /var/www/html/cacti, disabling the version installed by apt using the apache 2 command, but I only did it for the latest version, it was not necessary for function.

Code:
a2dissite cacti


The instance now works quite reliably with no errors or warning in the logs. It has been tested for the past week. I will re-post this solution referencing a few of the other database and php errors that were generated.


Top
 Profile  
 
 Post subject: Re: FATAL: Cannot connect to MySQL server on 'localhost'
PostPosted: Sun Feb 25, 2018 8:02 pm 
Offline
Cacti Guru User

Joined: Sun Aug 27, 2017 12:05 am
Posts: 1519
Ah, I see that other post is a replica of this one. I may download Mint and give it a test sometime this week then. Not sure why you would have those above issues, assuming you were just using the package versions? Or did you download the sources? Haven't looked back to check.

_________________
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  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 8 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