FATAL: Cannot connect to MySQL server on 'localhost'

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

Moderators: Developers, Moderators

Post Reply
jaro06
Posts: 7
Joined: Thu Feb 08, 2018 7:16 pm

FATAL: Cannot connect to MySQL server on 'localhost'

Post by jaro06 »

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.
netniV
Cacti Guru User
Posts: 3441
Joined: Sun Aug 27, 2017 12:05 am

Re: FATAL: Cannot connect to MySQL server on 'localhost'

Post by netniV »

Are you seeing any PHP errors in the log files or any other warnings?
Cacti Developer & Release Manager
The Cacti Group

Director
BV IT Solutions Ltd

+--------------------------------------------------------------------------+

Cacti Resources:
Cacti Website (including releases)
Cacti Issues
Cacti Development Releases
Cacti Development Documentation
jaro06
Posts: 7
Joined: Thu Feb 08, 2018 7:16 pm

Re: FATAL: Cannot connect to MySQL server on 'localhost'

Post by jaro06 »

No php errors, or any errors in /var/log/cacti/cacti, poller-error or rrd.log. The rest of the site works as expected.
User avatar
phalek
Developer
Posts: 2838
Joined: Thu Jan 31, 2008 6:39 am
Location: Kressbronn, Germany
Contact:

Re: FATAL: Cannot connect to MySQL server on 'localhost'

Post by phalek »

PHP errors need to be enabled first, so go to your php.ini file and enable it by uncommenting

Code: Select all

# error_log = syslog
to

Code: Select all

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 : CereusReporting
jaro06
Posts: 7
Joined: Thu Feb 08, 2018 7:16 pm

Re: FATAL: Cannot connect to MySQL server on 'localhost'

Post by jaro06 »

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

Re: FATAL: Cannot connect to MySQL server on 'localhost'

Post by jaro06 »

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
jaro06
Posts: 7
Joined: Thu Feb 08, 2018 7:16 pm

Re: FATAL: Cannot connect to MySQL server on 'localhost'

Post by jaro06 »

Having said that, doing:

Code: Select all

php5.6 poller.php
and updating /etc/crontab with php5.6 seems to have solved this issue.
netniV
Cacti Guru User
Posts: 3441
Joined: Sun Aug 27, 2017 12:05 am

Re: FATAL: Cannot connect to MySQL server on 'localhost'

Post by netniV »

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.
Cacti Developer & Release Manager
The Cacti Group

Director
BV IT Solutions Ltd

+--------------------------------------------------------------------------+

Cacti Resources:
Cacti Website (including releases)
Cacti Issues
Cacti Development Releases
Cacti Development Documentation
jaro06
Posts: 7
Joined: Thu Feb 08, 2018 7:16 pm

Re: FATAL: Cannot connect to MySQL server on 'localhost'

Post by jaro06 »

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: Select all

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: Select all

sudo a2dismod php7.1
sudo a2enmod php5.6
sudo service apache2 restart
Command Line:-

Code: Select all

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: Select all

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.
netniV
Cacti Guru User
Posts: 3441
Joined: Sun Aug 27, 2017 12:05 am

Re: FATAL: Cannot connect to MySQL server on 'localhost'

Post by netniV »

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.
Cacti Developer & Release Manager
The Cacti Group

Director
BV IT Solutions Ltd

+--------------------------------------------------------------------------+

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

Who is online

Users browsing this forum: No registered users and 2 guests