dotlinux blog

How to Install Cacti on Rocky Linux and AlmaLinux

Cacti simplifies network monitoring by automating data collection (via SNMP, scripts, or agents) and generating customizable graphs. It’s widely used by sysadmins to monitor:

  • Server resources (CPU, memory, disk)
  • Network devices (routers, switches, firewalls)
  • Services (HTTP, MySQL, DNS)

This guide focuses on Rocky Linux 8/9 and AlmaLinux 8/9—both binary-compatible with RHEL—ensuring stability and long-term support.

2026-03

Cacti is a powerful, open-source network monitoring and graphing tool that uses SNMP (Simple Network Management Protocol) to collect data from devices (routers, switches, servers, etc.) and RRDtool to generate visual graphs. It’s ideal for tracking metrics like bandwidth usage, CPU load, memory utilization, and more.

Rocky Linux and AlmaLinux—both RHEL (Red Hat Enterprise Linux) derivatives—are stable, secure, and enterprise-grade operating systems, making them perfect for hosting Cacti. This guide will walk you through installing Cacti on Rocky Linux 8/9 or AlmaLinux 8/9 with a detailed, step-by-step approach.

Table of Contents#

  1. Introduction
  2. Prerequisites
  3. Install LAMP Stack
  4. Configure MariaDB for Cacti
  5. Install Cacti Dependencies
  6. Download and Install Cacti
  7. Configure Apache for Cacti
  8. Complete Cacti Web Installation
  9. Set Up Cacti Poller Cron Job
  10. Configure SNMP for Monitoring
  11. Troubleshooting Common Issues
  12. Conclusion
  13. References

2. Prerequisites#

Before starting, ensure your system meets these requirements:

2.1 System Requirements#

  • OS: Rocky Linux 8/9 or AlmaLinux 8/9 (64-bit)
  • RAM: 2 GB minimum (4 GB recommended for large deployments)
  • CPU: 2 cores minimum
  • Storage: 10 GB minimum (more for historical data)
  • Network: Static IP address (for consistent access)

2.2 Update Operating System#

Always start with an updated system to avoid compatibility issues:

sudo dnf update -y && sudo dnf upgrade -y

2.3 Root or Sudo Access#

You’ll need sudo privileges to install packages and modify system settings.

3. Install LAMP Stack#

Cacti requires a LAMP stack (Linux, Apache, MariaDB, PHP) to run. Let’s install each component:

3.1 Install Apache Web Server#

Apache is the most popular web server for hosting Cacti:

sudo dnf install httpd -y

Start and enable Apache to run on boot:

sudo systemctl start httpd
sudo systemctl enable httpd

Allow Apache through the firewall (for web access):

sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload

Verify Apache is running:

sudo systemctl status httpd

You should see active (running) in the output.

3.2 Install MariaDB Database Server#

MariaDB (a fork of MySQL) stores Cacti’s configuration and historical data:

sudo dnf install mariadb-server -y

Start and enable MariaDB:

sudo systemctl start mariadb
sudo systemctl enable mariadb

Verify MariaDB is running:

sudo systemctl status mariadb

3.3 Install PHP and Required Extensions#

Cacti requires PHP 7.4+ (for Rocky/Alma 8) or 8.0+ (for Rocky/Alma 9).

For Rocky Linux 8 / AlmaLinux 8#

The default PHP version (7.2) is too old—use the Remi repository to install PHP 7.4:

# Install Remi repository
sudo dnf install dnf-utils -y
sudo dnf install https://rpms.remirepo.net/enterprise/remi-release-8.rpm -y
 
# Enable PHP 7.4
sudo dnf module reset php -y
sudo dnf module enable php:7.4 -y
 
# Install PHP and extensions
sudo dnf install php php-gd php-xml php-mbstring php-json php-snmp php-mysqlnd php-cli php-process php-zip -y

For Rocky Linux 9 / AlmaLinux 9#

The default PHP version (8.0+) is compatible—install directly:

sudo dnf install php php-gd php-xml php-mbstring php-json php-snmp php-mysqlnd php-cli php-process php-zip -y

Restart Apache to load PHP:

sudo systemctl restart httpd

Verify PHP is installed:

php -v

You should see a version ≥7.4.

4. Configure MariaDB for Cacti#

Now we’ll set up a database and user for Cacti, and import critical time zone data.

4.1 Secure MariaDB Installation#

Run the mysql_secure_installation script to harden MariaDB:

sudo mysql_secure_installation

Follow the prompts:

  1. Set root password: Enter a strong password (e.g., MySecurePass123!).
  2. Remove anonymous users: Type Y.
  3. Disallow remote root login: Type Y.
  4. Remove test database: Type Y.
  5. Reload privilege tables: Type Y.

4.2 Create Cacti Database and User#

Log into MariaDB as root:

mysql -u root -p

Enter your MariaDB root password when prompted.

Create a database for Cacti:

CREATE DATABASE cacti DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

Create a user with full access to the Cacti database:

CREATE USER 'cactiuser'@'localhost' IDENTIFIED BY 'StrongPassword123!';

Grant privileges to the user:

GRANT ALL PRIVILEGES ON cacti.* TO 'cactiuser'@'localhost';

Flush privileges to apply changes:

FLUSH PRIVILEGES;

4.3 Import Time Zone Tables (Critical!)#

Cacti requires MariaDB’s time zone tables to handle graphing correctly. Import them using:

sudo mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root -p mysql

Enter your MariaDB root password when prompted.

Next, grant the Cacti user access to the time zone tables:

mysql -u root -p

Run these SQL commands:

GRANT SELECT ON mysql.time_zone_name TO 'cactiuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;

4.4 Import Cacti Database Schema#

We’ll import Cacti’s default database schema later—first, we need to download Cacti (Step 6).

5. Install Cacti Dependencies#

Cacti relies on SNMP (for data collection) and RRDtool (for graphing). Install them:

sudo dnf install net-snmp net-snmp-utils rrdtool -y

6. Download and Install Cacti#

Download the latest stable version of Cacti from the official website:

wget https://www.cacti.net/downloads/cacti-latest.tar.gz

Extract the tarball:

tar xzf cacti-latest.tar.gz

Move the Cacti directory to Apache’s web root (/var/www/html):

sudo mv cacti-*/ /var/www/html/cacti

Verify the files are in place:

ls /var/www/html/cacti

7. Configure Apache for Cacti#

7.1 Set File Permissions#

Apache needs write access to Cacti’s files. Set the owner to the apache user:

sudo chown -R apache:apache /var/www/html/cacti

7.2 Adjust SELinux Policies#

SELinux (Security-Enhanced Linux) is enabled by default on Rocky/Alma. It restricts Apache’s access to files—fix this with:

  1. Set SELinux context for Cacti’s files:

    sudo semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/html/cacti(/.*)?"
    sudo restorecon -Rv /var/www/html/cacti
  2. Allow Apache to connect to MariaDB:

    sudo setsebool -P httpd_can_network_connect_db 1

7.3 Configure PHP Settings#

Cacti requires specific PHP settings (memory limit, execution time, time zone). Edit the php.ini file:

For Rocky/Alma 8 (PHP 7.4)#

sudo nano /etc/php/7.4/apache2/php.ini

For Rocky/Alma 9 (PHP 8.0+)#

sudo nano /etc/php/8.0/apache2/php.ini

Modify these values (replace America/New_York with your time zone):

memory_limit = 512M
max_execution_time = 300
date.timezone = America/New_York

Save and exit (Ctrl+O, Ctrl+X).

Restart Apache to apply changes:

sudo systemctl restart httpd

8. Complete Cacti Web Installation#

Now access the Cacti web installer to finalize setup.

  1. Open a browser and navigate to:

    http://your-server-ip/cacti
    

    Replace your-server-ip with your server’s static IP (e.g., 192.168.1.100).

  2. Welcome Screen: Click Next.

  3. License Agreement: Accept the GPL license and click Next.

  4. Prerequisites Check: Verify all requirements are met (green checkmarks). Click Next.

  5. Database Settings:

    • Database Type: MySQL
    • Database Name: cacti
    • Database Username: cactiuser
    • Database Password: The password you set for cactiuser (e.g., StrongPassword123!)
      Click Next.
  6. Template Setup: Select Default Templates (for most users) and click Next.

  7. Install Preview: Review the settings and click Install.

  8. Post-Install:

    • The installer will create tables and configure Cacti.
    • When done, click Get Started.
  9. Login: Use the default credentials:

    • Username: admin
    • Password: admin

    IMPORTANT: Change the admin password immediately after logging in!

9. Set Up Cacti Poller Cron Job#

Cacti uses a poller to collect data every 5 minutes. Set up a cron job for the apache user:

Open the cron editor:

sudo crontab -u apache -e

Add this line (runs the poller every 5 minutes):

*/5 * * * * php /var/www/html/cacti/poller.php > /dev/null 2>&1

Save and exit (Ctrl+O, Ctrl+X).

Verify the cron job is set:

sudo crontab -u apache -l

10. Configure SNMP for Monitoring#

To monitor devices, you need to enable SNMP on them. Let’s start with your Cacti server (to monitor itself):

10.1 Enable SNMP on the Cacti Server#

Edit the SNMP configuration file:

sudo nano /etc/snmp/snmpd.conf

Find the line starting with com2sec and change the community string (e.g., from public to MySNMPCommunity):

com2sec notConfigUser  default       MySNMPCommunity

Save and exit.

Restart SNMP and enable it on boot:

sudo systemctl restart snmpd
sudo systemctl enable snmpd

Allow SNMP through the firewall (UDP port 161):

sudo firewall-cmd --permanent --add-port=161/udp
sudo firewall-cmd --reload

10.2 Add a Device to Cacti#

Now add your server to Cacti for monitoring:

  1. Log into Cacti.
  2. Go to Console > Devices > Add.
  3. Device Settings:
    • Device Name: Your server’s name (e.g., Cacti-Server)
    • IP Address: 127.0.0.1 (localhost)
    • SNMP Version: SNMPv2
    • SNMP Community: The string you set (e.g., MySNMPCommunity)
  4. Click Create.

Cacti will automatically discover metrics (CPU, memory, disk) and generate graphs. Wait 5–10 minutes for the first graphs to appear.

11. Troubleshooting Common Issues#

11.1 Database Connection Error#

  • Cause: Incorrect credentials in config.php.
  • Fix: Edit /var/www/html/cacti/include/config.php and verify:
    $database_username = 'cactiuser';
    $database_password = 'StrongPassword123!';
    $database_name = 'cacti';

11.2 No Graphs Appearing#

  • Cause: Cron job not running, or RRDtool path incorrect.
  • Fix:
    1. Verify the cron job: sudo crontab -u apache -l.
    2. Check RRDtool path in Cacti: Console > Settings > Paths (should be /usr/bin/rrdtool).

11.3 SNMP Timeout#

  • Cause: Firewall blocking UDP port 161, or incorrect community string.
  • Fix:
    1. Test SNMP from the Cacti server: snmpwalk -v2c -c MySNMPCommunity localhost system.
    2. Ensure the remote device’s firewall allows UDP 161.

11.4 SELinux Permission Denied#

  • Cause: Incorrect SELinux context on Cacti files.
  • Fix: Reapply SELinux policies:
    sudo restorecon -Rv /var/www/html/cacti

12. Conclusion#

You’ve successfully installed Cacti on Rocky Linux or AlmaLinux! Now you can:

  • Add remote devices (routers, switches, servers) for monitoring.
  • Customize graphs and templates.
  • Set up alerts (using plugins like Thold).

Cacti is a robust tool—take time to explore its features and tailor it to your needs.

13. References#

  1. Cacti Official Documentation
  2. Rocky Linux Documentation
  3. AlmaLinux Documentation
  4. Remi Repository
  5. Net-SNMP Documentation
  6. RRDtool Documentation

Let me know if you have any questions—happy monitoring! 📊