Getting a “FATAL: Connection to Cacti database failed” when attempting to install Cacti on CentOS

I've nearly finished setting up Cacti on a headless VM CentOS server.

Apache is up, MySQL is up, all requisite PHP modules are installed.

When I browse to the server's IP, I can verify that httpd is working. Then when I navigated to <serverip>/cacti I got a forbidden message, which I resolved by modifying the http configuration file to allow connections from my IP. After this change, the new result of browsing to <serverip>/cacti is the following:

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.

Here are the configurations of my /include/config.php file:

$database_type     = 'mysql';
$database_default  = 'cacti';
$database_hostname = 'localhost';
$database_username = 'simpleuser';
$database_password = '******';
$database_port     = '3306';
$database_retries  = 5;
$database_ssl      = false;
$database_ssl_key  = '';
$database_ssl_cert = '';
$database_ssl_ca   = '';

Solution 1:

I've just struggled through this, and there are so many dead-end answers.

For me I needed to install both php7.3-intl and php7.3-mysql though yours might require php7.4-mysql.

Also I had to hard-set the PHP binary path using MySQL directly, because the system had PHP 7.4 whereas Cacti wanted PHP 7.3 and had assumed that /usr/bin/php was good enough.

 ~> mysql cacti -p -u cacti
 Enter password: xxxxx
 MariaDB [cacti]> select * from settings where name like '%php%'; 
 +-----------------+--------------+
 | name            | value        |
 +-----------------+--------------+
 | path_php_binary | /usr/bin/php |
 +-----------------+--------------+
 MariaDB [cacti]> update settings set value='/usr/bin/php7.3' where name='path_php_binary' ;
 MariaDB [cacti]> select * from settings where name like '%php%'; 
 +-----------------+-----------------+
 | name            | value           |
 +-----------------+-----------------+
 | path_php_binary | /usr/bin/php7.3 |
 +-----------------+-----------------+

You can get more info by running the poller in a shell:

caffeine:~#    su - www-data -s /bin/bash
www-data@caffeine:~$ php /usr/share/cacti/site/poller.php
....(errors, hopefully useful)....