Install Cacti on Ubuntu 20.04 LTS - Step by Step Process ?

Cacti is a network graphing solution based on RRDtool's framework. It collects and stores performance information to create graphs. It mostly uses SNMP for gathering information. It is mainly used to get CPU load and network bandwidth utilization in a graph format. 

Continuous monitoring keeps a tab on the health of IT systems and checks if all the components are running normally. Additionally, it helps operations teams to intervene in a timely manner and resolve issues in case something goes wrong. 

Here at LinuxAPT, as part of our Server Management Services, we regularly help our Customers to perform related System Monitoring Software on your Linux based server.

For more information about how to add and manage your devices, visit Cacti’s official documentation.

In this context, we shall look into the best procedure for installing Cacti on Ubuntu 20.04 LTS.

Steps to install Cacti on Ubuntu Linux System 

1. Install Prerequisites

To begin, we will update the repository index and then install some prerequisite packages.

Now, Execute the command below to update the repository index:

$ sudo apt update -y

Then use this command for installing the prerequisites:

$ sudo apt install unzip rrdtool git snmp php-snmp librrds-perl curl gnupg2 -y

2. Install LAMP server

Cacti also requires LAMP stack to be installed on your system. Use this command to install it:

$ sudo apt install mariadb-server php php-mysql apache2 libapache2-mod-php php-xml php-mbstring php-gmp php-ldap php-gd -y

Next, you are required to do is to open the php.ini file in a text editor using the command below:

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

Find and change the values of these lines:

memory_limit = 512M
max_execution_time = 60
date.timezone = Australia/Sydney

Now save the file and exit the editor.

Then open another php.ini file:

$ sudo nano /etc/php/7.4/cli/php.ini

Find and change the values of these lines:

memory_limit = 512M
max_execution_time = 60
date.timezone =

Now save the file and exit the editor.

As you have done the changes, so now restart the Apache service:

$ sudo systemctl restart apache2

3. Configure MariaDB Server

The database server used by Cacti is MariaDB. We will need to configure it.

Use the below command to edit the default configuration file of MariaDB server in Nano editor:

$ sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf

Add the below lines in this file:

collation-server = utf8mb4_unicode_ci
tmp_table_size = 64M
join_buffer_size = 64M
innodb_file_format = Barracuda
innodb_large_prefix = 1
max_heap_table_size = 128M
innodb_io_capacity = 5000
innodb_io_capacity_max = 10000
innodb_buffer_pool_size = 512M
innodb_flush_log_at_timeout = 3
innodb_read_io_threads = 32
innodb_write_io_threads = 16

Then, Save the file and exit the editor.

Now restart MariaDB using the command below:

$ sudo systemctl restart mariadb

Next, we will create a database and a user for Cacti. Enter into MariaDB server prompt using the command below:

$ sudo mysql

Create database named "cacti_db" using the command below:

$ create database cacti_db;

Then create a user named "cactiuser" with the password "123cacti" for Cacti:

$ GRANT ALL ON cacti_db.* TO cactiuser@localhost IDENTIFIED BY '123cacti';

Then use the command below to apply the changes you have made and then exit the MySQL prompt:

$ flush privileges;
$ exit;

Now grant database access to MySQL timezone:

$ sudo mysql mysql < /usr/share/mysql/mysql_test_data_timezone.sql

Now grant permission to the cactiuser to access the MySQL timezone. To do so, first enter into MariaDB server prompt using the command below:

$ sudo mysql

Then grant permission to cactiuser to access MySQL timezone:

$ GRANT SELECT ON mysql.time_zone_name TO cactiuser@localhost;

Then use the command below to apply the changes you have made and then exit the MySQL prompt.

$ flush privileges;
$ exit;

4. Install Cacti

Now download Cacti from its official Downloads page. Alternatively, you can use the below command to download the Cacti latest version 1.2.18 (as of August 2021):

$ wget

You can find the downloaded tar.gz file in your current Terminal directory.

Then extract the archive using the command below:

$ sudo tar -zxf cacti-1.2.18.tar.gz

The archive file cacti-1.2.18.tar.gz will be extracted to a new folder cacti-1.2.18. Move the contents of the directory to /var/www/html/cacti:

$ sudo mv cacti-1.2.18 /var/www/html/cacti

Now import the cacti database using the command below:

$ sudo mysql cactidb < /var/www/html/cacti/cacti.sql

Edit the config.php file:

$ sudo nano /var/www/html/cacti/include/config.php

Then modify the settings as follows:

$database_type = 'mysql';
$database_default = 'cacti_db';
$database_hostname = 'localhost';
$database_username = 'cactiuser';
$database_password = '123cacti';
$database_port = '3306';

Save the config.php file and close it.

Now change the Cacti directory owner using the command below:

$ sudo chown -R www-data:www-data /var/www/html/cacti/

Also, change the permissions:

$ sudo chmod -R 775 /var/www/html/cacti/

5. Create a Cron Job

Now create a cron job file to configure poller to gather information every 5 minutes. Use this command to create a cron job file:

$ sudo nano /etc/cron.d/cacti

Add the below line in the file:

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

Then save the cron file and close it.

6. Configure Apache

Now configure Apache virtual host file using the command below:

$ sudo nano /etc/apache2/sites-available/cacti.conf

In the file, add below lines:

Alias /cacti /var/www/html/cacti
<Directory /var/www/html/cacti>
Options +FollowSymLinks
AllowOverride None
<IfVersion >= 2.3>
Require all granted
<IfVersion < 2.3>
Order Allow,Deny
Allow from all
AddType application/x-httpd-php .php
<IfModule mod_php.c>
php_flag magic_quotes_gpc Off
php_flag short_open_tag On
php_flag register_globals Off
php_flag register_argc_argv On
php_flag track_vars On
php_value mbstring.func_overload 0
php_value include_path .
DirectoryIndex index.php

Now save the cacti.conf file and exit it.

Then run these commands:

$ sudo a2ensite cacti
$ sudo systemctl restart apache2

Then to verify if the Apache is running without any issues, use the command below:

$ sudo systemctl status apache2

7. Start the Cacti Initialization Wizard

  • Now access the following link in your web browser: http://server_ip/cacti
  • After accessing the above link, you will see the Cacti login page. To login, use admin as your login credentials.
  • Then the Change Password page will appear. You can set a new password here.
  • Then you will be presented with the license terms. Accept the terms and click Begin.
  • Hit Next.
  • Select the installation type and hit Next.
  • Hit Next.
  • Again, hit Next.
  • Check the box at the bottom and hit Next.
  • Chose your preferred options and hit Next.
  • When the Template Setup screen appears, make sure all templates are selected. Then hit Next.
  • Hit Next.
  • Check Confirm Installation box and click Install to initiate the installation process.
  • After the installation is finished, hit Get Started.
  • After that, the Cacti Dashboard console will appear on your screen.
  • Now in your Cacti Dashboard, you can create devices and start monitoring them.

[Need help in setting up Cacti on your Linux System? We can help you. ]

This article covers step by step procedure for installing the Cacti monitoring tool on Ubuntu 20.04 LTS. In fact, Cacti is a free and open-source RRD tool-based network monitoring tool that monitors network devices such as servers, routers, and switches. Cacti uses the SNMP protocol to gather data from remote systems. Data gathered is then stored in a MySQL database. 

One of the most essential tasks that any IT operation team has to keep in mind is continuous monitoring of their IT infrastructure. The concept of monitoring ensures that systems such as servers are functioning and working as desired.

Related Posts