How to Install and Configure Cacti on Ubuntu 20.04

Written by: Winnie Ondara   |   Last updated: July 23, 2022

Cacti is an open-source web-based network monitoring and system monitoring graphing tool. It is a frontend to RRDTool - a Time Series Database (TSDB).

Using Cacti you can monitor servers and network devices such as servers, routers, and switches. It gathers and monitors network traffic using the SNMP protocol. It can monitor various system metrics such as CPU, memory disk space, and bandwidth utilization among others. You can also set up alerts so that you receive email notifications in the event of a system outage. Furthermore, it enables a faster response time when a problem arises.

You can use LAMP stack to install Cacti on Linux Distribution. It also supports Nginx and IIS Webserver. The data collected is then stored in a MySQL or MariaDB database. The Data Collection framework is fully distributed, fault-tolerant and scalable.

In this guide, we will go through how to install and configure Cacti on Ubuntu 20.04.

Step 1: Install Apache webserver

Start off by updating your system packages with the following command:

sudo apt update -y

Cacti Monitoring tool is accessed via a web browser and we need to set up a web server. We will install the Apache2 webserver.

sudo apt install apache2 -y

Start and enable Apache with the commands:

sudo systemctl start apache2
sudo systemctl enable apache2

Step 2: Install MariaDB Database Server

Cacti stores all the data gathered from network devices in a database. In this guide, we will install MariaDB which is a robust open-source relational database, forked from MySQL.

MariaDB is available in the Ubuntu 20.04 repository. Simply install MariaDB with the following command:

sudo apt install mariadb-server mariadb-client

For Cacti to perform optimally, we need to tune the MariaDB database server. Access the 50-server.cnf configuration file.

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

Below the [ mysqld ] section, append the following lines:

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

Save and exit. Then, reload MariaDB for the changes to be applied.

sudo systemctl restart mariadb

Step 3: Install PHP and Required PHP Extensions

The front-end of the Cacti monitoring tool is completely PHP-driven. We must therefore install PHP and the associated PHP modules as shown:

sudo apt install libapache2-mod-php php-mysql php-xml php-gd php-snmp php-json php-intl php-mbstring php-ldap php-gmp -y

Next, adjust the max_execution time and memory limit and set your preferred timezone on /etc/php/7.4/apache2/php.ini and /etc/php/7.4/cli/php.ini files.

sudo vim /etc/php/7.4/apache2/php.ini
date.timezone = Africa/Nairobi
memory_limit = 512M
max_execution_time = 60

Similarly, replicate the changes in the /etc/php/7.4/cli/php.ini file.

Step 4: Install SNMP and RRDTool

In this step, we are going to install RRDtool and SNMP which are used in gathering and graphing system performance metrics. Run the following command:

sudo apt install rrdtool snmp snmpd snmp-mibs-downloader libsnmp-dev

Step 5: Create Cacti database

Cacti require a database to store all the data it collects. First, log in to MariaDB

sudo mysql -u root -p

Then create a database and a database user for cacti and grant all privileges to the user as shown:


GRANT ALL ON cactidb.* TO ‘cacti_user’@’localhost’ IDENTIFIED BY ‘cactipassword’;



Step 6: Download & Configure Cacti

Next, download the Cacti archive file from the official site as shown


At the time of writing this article, the latest Cacti version is version 1.2.18.

Then, create a Cacti directory in the /var/www/html/ as the web root directory for Cacti:

sudo mkdir /var/www/html/cacti

Extract the tar file to the above directory as shown:

sudo tar xzf cacti-latest.tar.gz -C /var/www/html/cacti

Next, set the cacti directory owner to the www-data webroot directory to as shown:

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

Next, import the default database to the cacti database.

sudo mysql -u root -p cactidb < /var/www/html/cacti/cacti.sql

Then, import the MySQL timezone data into MariaDB as shown

sudo mysql -u root -p mysql < /usr/share/mysql/mysql_test_data_timezone.sql

Now, head back to the MariaDB database

sudo mysql -u root -p

Grant select permissions to the cacti database user to access the mysql timezone. Run:

GRANT SELECT on mysql.time_zone_name to cacti_user@localhost;



Step 7: Configure Cacti Database Connection details

Now edit the Cacti configuration file. Open the config.php file.

sudo vim /var/www/html/cacti/include/config.php

Then, update the database details in the configuration file. Change the details to reflect the values you set when creating the database in Step 5 above.

$database_type = ‘mysql’;
$database_default = ‘cactidb’;
$database_hostname = ‘localhost’;
$database_username = ‘cacti_user’;
$database_password = ‘cactipasswd’;
$database_port = ‘3306’;

Step 8: Create Cacti Apache Configuration

In this step, we create a new virtual host file for the Cacti site.

sudo vim /etc/apache2/sites-available/cacti.conf

Add the following lines

Alias /cacti    /var/www/html/cacti
<Directory /var/www/html/cacti/>
  <IfModule mod_authz_core.c>
     Require all granted

Save and exit. Restart Apache for the changes to be applied

sudo systemctl restart apache2

Great. the only thing remaining now is to wind up with Cacti set up on a browser.

Step 9: Setting Up Cacti on a browser

We have completed all of the Cacti configurations at this time. Now we have to finish the Cacti installation in a web browser. The Cacti setup wizard will lead you through the process step by step.
Access cacti using the following address:


A login page will be displayed as shown below. Login with the default credentials:

Username: admin

Password:  admin

default cacti login page

Next, you will be prompted to reset your password. Make sure you set a strong password for security reasons and click on the 'Save' button.

Cacti change password

Next, agree to the GPL license in the checkbox. Click on ‘Begin’ to continue with the installation.

Cacti accept license agreement

Cacti will then run pre-installation checks to ensure that your system has the necessary PHP modules and database settings for cacti to function properly. If all the configurations are in order, click 'Next.'

cacti preinstallation check

Next, select the 'New Primary Server' installation option and double-check that the local database connection parameters are correct before proceeding. Click Next. 

cacti local database connection details

BE sure to check that the directory permission checks are correct, then click 'Next.' If not, return to Step 6 and set the permissions as directed.

cacti directory permission checks

Next, ensure that the critical binary paths and versions details displayed are correct and click ‘Next'.

Cacti critical binary locations and versions

In the next step, an overview of input validation whitelist protection is displayed. It suggests a couple of steps to take in order to whitelist data input methods. Check the 'I have read this statement' box to proceed with the installation.

cacti input validation whitelist protection

The next step lets you select the data source profiles for polling sources. You can also change the network range to correspond to your subnet.

cacti default Automation network

Cacti provides templates for monitoring and graphing a variety of devices such as routers, Linux, and Windows servers. By default, all settings are checked to ensure that you get all of the templates you require.  Click ‘Next’ to proceed. 

Cacti default template setup

Next, the installer will verify if the server and database collation is UTF8 compliant. Click ‘Next’.

Cacti server and database collation

Next, check the ‘Confirm installation’ box and click the ‘Install’ button to kick off the installation process.

Cacti confirm installation

The installation gets underway and should take around a minute to complete.

Cacti server installation

If the installation is successfully completed, the following screen will be displayed.

Cacti installation complete

Click on the ‘Get started' button.  Cacti is now up and running. The Cacti dashboard is displayed as shown below:

Cacti default dashboard


You have now successfully installed and configured Cacti on Ubuntu 20.04. You can now start adding your devices and monitoring them.

About The Author

Winnie Ondara

Winnie Ondara

Winnie is a Linux technical writer with over 3 years of experience with various Linux distributions and writing technical guides in Linux. She is passionate about FOSS technologies and always endeavor to learn new technologies. During my free time, I watch movies, listen to music, and catch up with tech news.



Please add comments below to provide the author your ideas, appreciation and feedback.

Leave a Reply

Leave a Comment