Installing Cacti on FreeBSD

Cacti is an open-source network monitoring tool that allows you to collect data from a variety of sources and graph it over time. In this tutorial, we will walk through the steps to install Cacti on FreeBSD.

Prerequisites

  • A FreeBSD server with root access
  • A valid internet connection

Step 1: Update Your System

Before installing any new software, it’s important to update your system to the latest version. This can be done by running the following command:

freebsd-update fetch install

Step 2: Install Required Packages

The following packages are required for installing Cacti:

pkg install apache24 mysql57-server php74 php74-extensions php74-gd php74-mysqli php74-xml php74-zlib php74-bcmath php74-ctype php74-session php74-json php74-filter php74-hash php74-opcache php74-pdo php74-pdo_mysql php74-simplexml net-snmp

Step 3: Configure MySQL Server

Start the mysql service at boot time:

echo 'mysql_enable="YES"' >> /etc/rc.conf

Initialize the MySQL data directory:

/usr/local/etc/rc.d/mysql-server initialize

Start the MySQL service:

service mysql-server start

Set the root password:

mysql_secure_installation

Step 4: Configure Apache Web Server

Start the apache service at boot time:

echo 'apache24_enable="YES"' >> /etc/rc.conf

Start the Apache service:

service apache24 start

Step 5: Download and Install Cacti

Download the latest version of Cacti from the official website:

cd /usr/local/www
fetch https://www.cacti.net/downloads/cacti-latest.tar.gz
tar -zxvf cacti-latest.tar.gz
mv cacti-* cacti

Step 6: Configure Cacti

Create a new database and user for Cacti:

mysql -u root -p
CREATE DATABASE cacti;
CREATE USER 'cactiuser'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON cacti.* TO 'cactiuser'@'localhost';
FLUSH PRIVILEGES;
exit

Import the Cacti database template:

cd /usr/local/www/cacti
mysql -u cactiuser -p cacti < cacti.sql

Edit the Cacti configuration file:

cp include/config.php.dist include/config.php
vi include/config.php

Update the database settings with the following:

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

Step 7: Configure Apache for Cacti

Create a new virtual host file for Cacti:

cp /usr/local/etc/apache24/Includes/cacti.conf.sample /usr/local/etc/apache24/Includes/cacti.conf
vi /usr/local/etc/apache24/Includes/cacti.conf

Update the Apache virtual host settings with the following:

Alias /cacti /usr/local/www/cacti
<Directory "/usr/local/www/cacti/">
    Order allow,deny
    Allow from all
</Directory>

Restart the Apache service:

service apache24 restart

Step 8: Accessing Cacti

To access Cacti, open a web browser and navigate to the following URL:

http://your_server_ip/cacti/

You should now be able to log in to Cacti with the default username ‘admin’ and the password ‘admin’.

Congratulations, you have successfully installed Cacti on FreeBSD!