Am facing this error on my cacti installation after running “yum update on the system”
FATAL: Connection to Cacti database failed. Please ensure:
Troubleshooting “Connection to Cacti database failed” Error After yum update
Experiencing a “Connection to Cacti database failed” error after a yum update
can be frustrating. Let’s troubleshoot this together. Here are the likely causes and how to check them:
1. PHP MySQL Module
What it is:
Cacti uses PHP to communicate with the MySQL database. The php-mysql
module (or a similar name depending on your PHP version) is essential for this connection.
How to check:
- Run the following command in your terminal:
bash
php -m | grep mysql
- Expected Output: You should see
mysql
ormysqli
listed. If not, the module is likely missing or not enabled.
How to fix (if missing):
- Install the module using
yum
. The exact package name might vary based on your PHP version. Try these commands:bash
sudo yum install php-mysql
sudo yum install php-mysqli
- After installation, restart your web server (e.g., Apache or Nginx) and PHP-FPM (if you’re using it) to load the new module:
bash
sudo systemctl restart httpd # For Apache
sudo systemctl restart nginx # For Nginx
sudo systemctl restart php-fpm # If using PHP-FPM
2. MySQL Database Status
What it is:
The MySQL database server needs to be running for Cacti to connect.
How to check:
- Run the following command:
bash
sudo systemctl status mariadb # Or mysql, depending on your MySQL distribution
- Expected Output: The status should indicate that the service is
active (running)
. If not, you’ll see an error or inactive status.
How to fix (if not running):
- Start the MySQL service:
bash
sudo systemctl start mariadb # Or mysql
- If it fails to start, check the MySQL error logs for more details. The log file is usually located in
/var/log/mysqld.log
or/var/log/mariadb/mariadb.log
.
3. Cacti Configuration (config.php)
What it is:
The config.php
file in your Cacti installation directory contains the database connection details (hostname, username, password, database name). If these are incorrect, Cacti won’t be able to connect.
How to check:
- Locate your Cacti installation directory. It’s often in
/var/www/html/cacti
or/usr/share/cacti
. - Open the
config.php
file with a text editor (usingsudo
if necessary):bash
sudo nano /path/to/cacti/config.php
- Look for the following lines and verify their values:
php
$database_type = 'mysql'; // Or 'mysqli'
$database_hostname = 'localhost'; // Or your database server IP/hostname
$database_username = 'your_cacti_username';
$database_password = 'your_cacti_password';
$database_default = 'cacti';
$database_port = '3306'; // Usually 3306 for MySQL
- Important: Double-check the username and password. They are case-sensitive.
How to fix (if incorrect):
- Carefully edit the incorrect values in
config.php
to match your MySQL database credentials. - Save the file and restart your web server and PHP-FPM (if applicable).
Why did this happen after yum update
?
A yum update
can sometimes upgrade packages like PHP or MySQL. This might lead to:
- PHP MySQL module being disabled or uninstalled: The update process might replace configuration files or remove older packages.
- MySQL service restarting or encountering issues: Although less common, an update could trigger a restart or introduce a configuration change that prevents MySQL from starting correctly.
- Configuration file changes (less likely for Cacti’s
config.php
but possible for related services): While unlikely to directly modify Cacti’s config, updates to other components could indirectly cause issues.
Steps to Take:
- Start with the PHP MySQL module check. It’s a common culprit after PHP updates.
- Verify the MySQL database status. Ensure it’s running.
- Carefully review the
config.php
file. Double-check the credentials. - Restart relevant services (web server, PHP-FPM, MySQL) after making any changes.
- Check the Cacti logs (usually in the
log
subdirectory within your Cacti installation) for any specific error messages.
Let me know the output of the commands above, especially the php -m | grep mysql
and sudo systemctl status mariadb
(or mysql
) commands, and the contents of the database-related lines in your config.php
(please redact the actual password!). This will help me narrow down the issue and provide more specific guidance. Good luck!