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.

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. 

Table of Contents

    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.

    Along with collecting data,  Cacti provides the RRDtool, short for RoundRobin Database tool, which logs and graphs data on dashboards. The front-end is driven by PHP. With Cacti, you can monitor various network setups: from a small LAN-sized networks to complex networks with hundreds of devices.

    In this guide, we walk you through the installation of Cacti on Ubuntu 20.04 LTS. At the time of penning down this guide, the latest version of Cacti is Cacti 1.2.16. Without much further ado, let us dive in.


    Before getting started, perform a flight-check and ensure you have the following:

    1. An instance on Ubuntu server 20.04 LTS with SSH access.
    1. A sudo user configured on the system.
    1. A stable internet connection.

    Step 1: Install Apache web server

    Right off the bat, being by updating the system package lists as shown:

    $ sudo apt update -y

    Since Cacti runs on the front end, we need to spin up a web server. An excellent choice for a web server is Apache, which is a free and open-source feature-rich web server.

    To install Apache, execute:

    $ sudo apt install apache2 -y

    To check if Apache is running, invoke the command:

    $ sudo systemctl status apache2

    If Apache is not running, you can start it and enable it on boot time as shown.

    $ sudo systemctl start apache2
    $ sudo systemctl enable apache2

    If you are behind a UFW firewall, you can allow HTTP protocol as follows:

    $ sudo ufw allow http


    $ sudo ufw allow 80/tcp

    Then reload the firewall to have the changes take effect.

    $ sudo ufw reload

    Another way of verifying that Apache is running is heading over to your browser and visiting your server’s IP address as shown:


    You should get the default Apache welcome page as shown.

    Step 2: Install MariaDB Database Server

    As earlier mentioned, Cacti requires a database to store all of the data it collects from network devices. In this guide, we have chosen to go with MariaDB database, which is a fork of MySQL. MariaDB is an opensource  community developed and maintained database server which is more secure and robust than MySQL.

    Ubuntu 20.04 contains MariaDB packages in its repositories. Therefore, you can easily install MariaDB using APT package manager as shown:

    $ sudo apt install mariadb-server mariadb-client

    Once the installation is complete, the database server should automatically start running. To confirm this, invoke the command below:

    $ sudo systemctl status mariadb

    As you can see from the output above, MariaDB is active and running.

    If by any chance MariaDb is inactive,  start  and enable the database server as shown.

    $ sudo systemctl start mariadb
    $ sudo systemctl enable mariadb

    By default, MariaDB  database settings are insecure  and can be exploited by hackers to gain remote access to the database server. Therefore you need to go a step further and carry out database hardening tasks by executing the  mysql_secure_installation script as shown.

    $ sudo mysql_secure_installation

    Firstly, you will be required to set the root password for the database. Press ‘Y’ for Yes and hit ENTER to continue.

    For subsequent prompts, simply press ‘Y’ to set the recommended security options.

    A few tweaks are required for optimization of MariaDB database server. Therefore, edit the  50-server.cnf configuration file as follows:

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

    Make the following changes  under the [mysqld] section.

    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 = 512M
    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 the file.  Thereafter, restart MariaDB for the changes to come into effect.

    $ sudo systemctl restart mariadb

    Step 3: Create Cacti database

    Cacti requires a database where all the polled data will be stored. Log in to MariaDB.

    $ sudo mysql -u root -p

    Then create the database as shown:

    CREATE DATABASE cacti_db CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

    Next, create a database user and grant all privileges on the user:

    GRANT ALL ON cacti_db.* TO ‘user’@’localhost’  IDENTIFIED BY ‘password’;

    Finally, save the changes and exit MariaDB:


    At this point, we have installed and fully configured the database server. 

    Step 3: Install  PHP and Associated PHP Extensions

    Cacti is PHP driven and it’s essential to install PHP and the required modules for Cacti to function as expected. The default PHP version in Ubuntu repositories is PHP 7.4 at the time of writing this tutorial. The latest PHP version is PHP 8.0 but version 7.4 will work as expected.

    To install the default PHP version and associated extensions from Ubuntu repositories, run:

    $ 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

    You can verify the version of PHP installed by running the command:

    $ php -v

    Next, configure your preferred time zone, max_execution time and memory limit by editing 2 files:  /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

    Edit the following lines and specify the timezone, memory_limit and max_execution_time parameters.

    date.timezone = Africa/Nairobi
    memory_limit = 512M
    max_execution_time = 60

    Likewise, edit the /etc/php/7.4/cli/php.ini file and go with the same values above.

    Step 4: Install  SNMP and RRDTool

    Cacti requires net-snmp and RRDTool for  logging and graphing data on dashboards which are displayed on the front-end. To install these utilities, execute the command:

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

    Step 5: Download & Configure Cacti

    So far, we are done installing the prerequisite components that underpin Cacti. In this section, we will focus on downloading and configuring Cacti.

    To start off, download the Cacti compressed file from the official Cacti site using the wget command as shown.

    $ wget

    Next, create a webroot directory as  the  /var/www/html/cacti as the web root directory for Cacti:

    $ sudo mkdir /var/www/html/cacti

    Extract the contents of Cacti compressed tarball file to the web root directory:

    $ sudo tar xzf cacti-latest.tar.gz -C /var/www/html/cacti –strip-components=1

    Be sure to set permissions of the www-data webroot directory to as shown:

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

    Next, import the default database to the new cacti database.

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

    Afterwards, import the timezone data into MariaDB database server.

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

    Once done, log in to MariaDB database as shown.

    $ sudo mysql -u root -p

    And thereafter, grant SELECT permissions to the cacti database user. Then save and exit the database server.

    $ grant select on mysql.time_zone_name to user@localhost;

    Step 6: Configure Cacti Database Connection details

    In this step, you need to edit the Cacti configuration file. Use your preferred text editor to open the config.php file as shown.

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

    Next, update the database details as shown. Be sure to use values that match your database host, user and password.

    $database_type = ‘mysql’;
    $database_default  = ‘cacti_db’;
    $database_hostname = ‘localhost’;
    $database_username = ‘user’;
    $database_password = ‘P@ssword123’;
    $database_port = ‘3306’;

    Save and exit.

    Step 8: Create Cacti Apache Configuration

    Next, create a new virtual host file for the Cacti site.

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

    Edit the file by adding the lines below.

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

    Save and quit the file. To verify if Apache’s configuration is error-free , execute the command:

    $ sudo apachectl configtest

    If the settings are sound, you should get a ‘Syntax OK’ output as shown.

    Finally, to apply the changes, restart Apache web server as shown.

    $ sudo systemctl restart apache2

    Step 9:  Set Up Cacti Using Web Browser

    At this point, we are done with all the Cacti configurations. The only part remaining is to complete the Cacti setup on a web browser. This will be a guided step-by-step procedure made possible by the Cacti setup wizard.

    So, fire up your browser and go to the following address:


    This presents a login page shown. Use the following credentials :

    Username: admin
    Password:  admin

    Don’t worry about the credentials being too weak. You will later be required to reset the password in the next step. For now, enter the default values and hit the ‘login’ button to proceed to the next step.  

    In this section, you will be prompted to set a new password of your choice. Be sure to set a strong password that comprises multi-case and special characters and click ‘Save’.

    Next,  skim through the License agreement and Accept the GPL license agreement. Then click the ‘Begin’ button to proceed.

    Cacti then performs some pre-installation checks to verify if all the PHP extensions are installed and MySQL settings are sound. Click ‘Next’.

    The next step gives you the freedom to select 2 installation options. By default, the New Primary server is selected. Additionally, you get a glimpse of the database details. Simply go with the default selections and click ‘Next’.

    Ensure the directory permission checks are okay and click ‘Next’. If not, head back and set the permissions as indicated in Step 5.

    Next, check if  all the critical binary locations and versions are correct and click ‘Next’.

    Cacti 1.2.16 has introduced another step that provides an overview of validation of data input methods and how you can use a validation script in the cacti directory to validate these input methods. Go over the instructions, check off the ‘I have read this statement’ checkbox option and hit ‘Next’.

    The next step allows you to specify the data source profiles for polling resources and the network range. You can change the network range to suit your subnet and go with the rest of the default options.

    The ‘template setup’ step gives you an overview of the various device templates that are available and selects all of them by default. Just click ‘Next’.

    In the next step, click ‘Next’ to start converting the outlined tables to UTF-8 and InnoDB with Dynamic row format.

    Next, click ‘Confirm installation and thereafter ‘Install’ to start the installation process.

    The installation starts and should take about a minute or so to get completed.

    If all went well, you will get a notification that the installation completed successfully and a process log will be displayed. 

    Click on the ‘Get started’ button and this takes you to the Cacti dashboard.

    And this marks the end of the installation process for the Cacti network monitoring tool. 


    As you have seen, installation of Cacti is a multi-stage process that requires a lot of attention to detail. Hopefully, at this point, you are able to install Cacti on Ubuntu 20.04. You can proceed and add your devices for monitoring. We will be posting a followup article soon on how to monitor devices using Cacti.