Share on Social Media

In this article, you will learn how to install Cacti on CentOS 8. This article provides the complete installation steps including SELinux configuration. #centlinux #linux #cacti

What is Cacti? :

Cacti is an open-source, web-based network monitoring and graphing tool designed as a front-end application for the open-source, industry-standard data logging tool RRDtool.

Cacti uses a Poller to collect system metrics at a predetermined intervals and graph the resulting data. Cacti can use one of two back ends: “cmd.php”, a PHP script suitable for smaller installations, or “Spine” (formerly Cactid), a C-based poller which can scale to thousands of hosts.

The front end can handle multiple users, each with their own graph sets, so it is sometimes used by web hosting providers to display bandwidth statistics for their customers. Cacti can be extended to monitor any source via shell scripts and executables.

Cacti is maintained by The Cacti Group, Inc. and distributed under GNU GPL license.

Read Also: Install Cacti on Rocky Linux 9

Cacti Features:

Some of the popular features of Cacti network monitoring software are:

  • unlimited graph items
  • auto-padding support for graphs
  • graph data manipulation
  • flexible data sources
  • data gathering on a non-standard timespan
  • custom data-gathering scripts
  • built-in SNMP support
  • graph, devices and data sources templates
  • tree, list, and preview views of graph data
  • user and user group based management and security
  • remote data collection
  • graph aggregation
  • device, graph and tree automation
  • network discovery

Environment Specification:

We are using a minimal CentOS 8 KVM machine with following specification.

  • CPU – 3.4 Ghz (2 cores)
  • Memory – 2 GB
  • Storage – 20 GB
  • Operating System – CentOS 8.2
  • Hostname –
  • IP Address – /24

Upgrade Linux Software Packages:

Connect with as root user by using a ssh tool.

First of all, we are upgrading the existing software packages of our CentOS 8 server.

# dnf update -y

Our CentOS 8.1 machine has been upgraded to CentOS 8.2. We can confirm it by using following commands.

# uname -a
Linux 4.18.0-193.6.3.el8_2.x86_64 #1 SMP Wed Jun 10 11:09:32 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

# cat /etc/redhat-release
CentOS Linux release 8.2.2004 (Core)

You can follow our previous post to upgrade CentOS 7 to 8 Server.

Install Apache on CentOS 8:

Cacti network monitoring server is a PHP based web application, therefore, we need a PHP supported web browser to run it.

We are using the popular Apache HTTP Server for this purpose.

# dnf install -y httpd httpd-devel

Enable and start Apache service.

# systemctl enable --now httpd.service
Created symlink /etc/systemd/system/ â /usr/lib/systemd/system/httpd.service.

Allow the Apache Service in Linux firewall, to make it accessible from the network computers.

# firewall-cmd --permanent --add-service=http
# firewall-cmd --reload

Install MariaDB on CentOS 8:

Cacti requires a MySQL database for its metadata repository. Therefore, we are installing MariaDB server. Please follow our previous article, if you want to install latest version of MariaDB on CentOS 8.

# dnf install -y mariadb-server

Enable and start MariaDB database service.

# systemctl enable --now mariadb.service
Created symlink /etc/systemd/system/mysql.service â /usr/lib/systemd/system/mariadb.service.
Created symlink /etc/systemd/system/mysqld.service â /usr/lib/systemd/system/mariadb.service.
Created symlink /etc/systemd/system/ â /usr/lib/systemd/system/mariadb.service.

Configure MariaDB Server and set the password of root user.

# mysql_secure_installation


In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] Y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
 ... Success!

By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] Y
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] Y
 ... Success!

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] Y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] Y
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

Install PHP on CentOS 8:

Cacti is developed in PHP programming language, thus it requires a PHP supported web server to run. We have already installed Apache HTTP Server and now we are installing PHP on CentOS 8.

# dnf install -y php-fpm php-common php-mysqlnd php-xml php-ldap php-json php-cli php-gd php-gmp php-mbstring php-process

Enable and start PHP-FPM Service.

# systemctl enable --now php-fpm.service
Created symlink /etc/systemd/system/ â /usr/lib/systemd/system/php-fpm.service.

Install SNMP on CentOS 8:

SNMP (Simple Network Management Protocol) is an Internet standard protocol for collecting and organizing information about managed devices on IP networks.

Install net-snmp and net-snmp-utils packages to install SNMP and php-snmp to enable PHP support for SNMP.

# dnf install -y net-snmp php-snmp net-snmp-utils

Install RRDTool on CentOS 8:

Cacti requires RRDTool (RRD stands for Round Robin Database) for maintaining system metrics data. Therefore, we are installing rrdtool package using dnf command.

# dnf install -y rrdtool

Configure PHP Settings for Cacti:

To use Cacti network monitoring server, we need to customize PHP settings accordingly.

Edit /etc/php.ini configuration file and configure it for using Cacti.

# vi /etc/php.ini

Locate and set following parameters therein.

safe_mode = Off                 ; Disable safe mode
date.timezone = "Asia/Karachi"  ; Define timezone to avoid warnings on time/date functions
file_uploads = On               ; Allow import of templates
memory_limit = 400M             ; maximum amount of memory a PHP script can consume
max_execution_time = 60         ; maximum execution time (in seconds) of a PHP script

Install Cacti on CentOS 8:

We are downloading latest stable version of Cacti from their official website.

# cd /tmp
# wget
--2020-06-19 09:50:55--
Resolving (,,, ...
Connecting to (||:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 25126474 (24M) [application/octet-stream]
Saving to: âcacti-1.2.12.tar.gzâ

cacti-1.2.12.tar.gz 100%[===================>]  23.96M  2.34MB/s    in 11s

2020-06-19 09:51:08 (2.12 MB/s) - âcacti-1.2.12.tar.gzâ saved [25126474/25126474]

Extract downloaded tarball into default DOCUMENT_ROOT.

# tar -C /var/www/html -xzf cacti-1.2.12.tar.gz
# cd

Rename the Cacti directory to a simple name for easy accessibility.

# mv /var/www/html/cacti-1.2.12 /var/www/html/cacti

Create a MariaDB Database for Cacti:

Connect with MariaDB server as root user.

# mysql -u root -p123
Welcome to the MariaDB monitor.  Commands end with ; or g.
Your MariaDB connection id is 8
Server version: 10.3.17-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.

MariaDB [(none)]>

Create a database for Cacti network monitoring server.

MariaDB [(none)]> create database cacti CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
Query OK, 1 row affected (0.112 sec)

Create a user for Cacti software and grant complete rights on cacti database.

MariaDB [(none)]> GRANT ALL ON cacti.* TO cacti@localhost IDENTIFIED BY 'Str0ngPa55word';
Query OK, 0 rows affected (0.254 sec)

Grant Time Zone selection privilege to cacti user.

MariaDB [(none)]> GRANT SELECT ON mysql.time_zone_name TO cacti@localhost;
Query OK, 0 rows affected (0.042 sec)

Reload privileges tables.

Query OK, 0 rows affected (0.083 sec)

Exit from MySQL shell.

MariaDB [(none)]> QUIT

Cacti tarball also contains a SQL script for creating the necessary database objects. We can use this script to create tables and other objects in the cacti database.

# mysql -D cacti -u cacti -pStr0ngPa55word < /var/www/html/cacti/cacti.sql

Before moving forward, we need to load the MariaDB timezone tables. Otherwise, the Cacti web installer will give you warning on timezones.

Use following command to load timezone tables with available timezones from CentOS 8 operating system.

# mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root -p123 mysql
Warning: Unable to load '/usr/share/zoneinfo/leapseconds' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/tzdata.zi' as time zone. Skipping it.

Timezones has been successfully loaded into MariaDB tables. Don’t worry about the warnings, it is because these files do not contain a valid timezone.

Edit MariaDB configuration file.

# vi /etc/my.cnf.d/mariadb-server.cnf

Set following global variables under [mysqld] section, as required by Cacti network monitoring software.


Configure Cacti on CentOS 8:

Edit config.php file and update parameters according to your environment.

# vi /var/www/html/cacti/include/config.php

Locate and update following parameters.

$database_username = 'cacti';
$database_password = 'Str0ngPa55word';

Make apache user as owner of the Cacti software directory.

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

Restart Apache and PHP services to apply changes.

# systemctl restart httpd.service php-fpm.service

Configure SELinux for Cacti:

Install required SELinux commands i.e. semanage by using dnf command..

# dnf install -y policycoreutils-python-utils-2.9-9.el8.noarch

Configure SELinux to allow read/write on the following directories.

# semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/html/cacti/log(/.*)?"
# semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/html/cacti/resource/snmp_queries(/.*)?"
# semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/html/cacti/resource/script_server(/.*)?"
# semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/html/cacti/resource/script_queries(/.*)?"
# semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/html/cacti/scripts(/.*)?"
# semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/html/cacti/cache/boost(/.*)?"
# semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/html/cacti/cache/mibcache(/.*)?"
# semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/html/cacti/cache/realtime(/.*)?"
# semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/html/cacti/cache/spikekill(/.*)?"
# semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/html/cacti/rra(/.*)?"

Reapply the filecontexts on the cacti directory.

# restorecon -R /var/www/html/cacti/

Configure a cron job to run poller.php script in every 5 minutes. This script will collect and update the system metrics in /rra directory.

# echo  "*/5 * * * *    apache   /usr/bin/php /var/www/html/cacti/poller.php > /dev/null 2>&1" >> /etc/crontab

Open URL in a client’s browser such as Google Chrome.

Cacti Web Login

Login by using default username/password i.e. admin/admin

Cacti Web Change Password

Since, we are login to Cacti web interface for the first time, therefore, we are required to change the default password of admin user.

Cacti License Agreement

Read and accept the License Agreement of Cacti network monitoring software.

Cacti Prerequisites Check

If you have followed the installation steps in this article correctly, then you won’t found any warning on this page.

We are skipping a warning about innodb_buffer_pool_instances, a MariaDB global variable, because we are installing MariaDB on a machine with limited memory. If you install MariaDB on a machine with more than 1 GB RAM available for InnoDB buffer, you won’t see this warning.

Cacti Installation Type

Choose your preferred installation type. Since, this is our first Cacti server therefore, we have selected “New Primary Server”.

Cacti Permission Check

If you have configured the SELinux correctly, then there won’t be any warnings.

Cacti critical Binary Locations and Versions

Setup is checking for required binaries, their locations and required versions.

Cacti Input Validation Whitelist Protection

Setup will inform you about a security concern and how to handle it. Accept it and continue.

Cacti Default Profile

Adjust your default profile and continue.

Cacti Template Setup

Select the required device templates and continue.

Cacti Server Collation

Setup is checking the MariaDB server and database collation.

Cacti Confirm Installation

If your configurations are fine, then Cacti setup will display this page and it will ask you to start installation.

Installing Cacti Server
Cacti Installation Process Log

We have successfully install Cacti on CentOS 8.

Cacti Dashboard

After successful installation, you will reached at the Cacti Dashboard.

Cacti Graphs

You can see some graphs by clicking on the Graphs tab.

Read Also: How to install Cacti on Rocky Linux 9

Conclusion – Install Cacti on CentOS 8:

In this article, you have learned how to install Cacti on CentOS 8. Before you begin using the Cacti network monitoring server, we recommend that you should read Cacti Beginner’s Guide – Second Edition (PAID LINK) by Packt Publishing. It will be really helpful to understand the Cacti web interface and it’s usage.

7 thoughts on “How to install Cacti on CentOS 8”
  1. Indeed, i followed so many articles, but this one went through without any issues. Seamless and clear instructions with snapshots. Many thanks for the publisher.

  2. I changed the data directory location in database, how to change socket location in php?
    PHP Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/app/cactiserver/cactidb/mysql/mysql.socket' (2)' in Command line code:1
    Stack trace:
    #0 Command line code(1): PDO->__construct('mysql:host=loca…', 'cactiuser', 'Cacti*102030')
    #1 {main}
    thrown in Command line code on line 1

  3. I made changes to below parameter and then database connection was successful.
    change database_hostname = "localhost";
    to database_hostname = "";

Leave a Reply

Your email address will not be published. Required fields are marked *