Cacti on FreeBSD – the setup

I’m going to make a new cacti server using the latest, greatest FreeBSD, Apache, PHP, MySQL and Cacti. My old server was migrated in using the dump and restore into vmware method documented earlier. Now its time to move on, so here is the method:

1. Setup FreeBSD

Install FreeBSD 9.0 from CD/DVD/Key. Then we need to update everything – I noticed that the version of Cacti was quite outdated in the stock version. Here goes:

pkg_add -r cvsup-without-gui
mkdir /usr/cvs
ee /usr/cvs/ports-supfile
add:
===/===
*default host=cvsup.uk.FreeBSD.org
*default base=/usr
*default prefix=/usr
*default release=cvs
*default tag=RELENG_9_0
*default delete use-rel-suffix
src-all
*default tag=.
ports-all
doc-all
*default compress
===/===

/usr/local/bin/cvsup /usr/cvs/ports-supfile

cd /usr/src
make buildworld; make installworld; make buildkernel; make installkernel; reboot

Now thats complete we can install the software:

2. Install Software:

cd /usr/ports/www/apache22
make install (accept all defaults) 
echo 'apache22_enable="YES"' >> /etc/rc.conf
/usr/local/etc/rc.d/apache22 start

cd /usr/ports/lang/php5
make install (ensure the apache module is checked)

Edit the apache config to allow php. I added at line 362

ee /usr/local/etc/apache22/httpd.conf
===/add/===
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
===/===

/usr/local/etc/rc.d/apache22 restart

Now add the MySQL

cd /usr/ports/databases/mysql55-server/
make install

echo 'mysql_enable="YES"' >> /etc/rc.conf
/usr/local/etc/rc.d/mysql-server start

3. Secure MySQL
We need to secure MySQL to start with by adding a root password, and i also allow management from the outside (%) but use the firewall to control access.

/usr/local/bin/mysql -u root

SET PASSWORD FOR 'root'@'localhost' = PASSWORD('super_secret');
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'super_secret';

4. Install Cacti
Now install cacti from the port

cd /usr/ports/net-mgmt/cacti
make install (accept defaults)

5. Do the MySQL setup for Cacti
First login as root and follow the details below:

# /usr/local/bin/mysql -u root -p

create database cacti;
GRANT ALL ON cacti.* TO cacti@localhost IDENTIFIED BY 'cacti';
FLUSH PRIVILEGES;
exit

Now we need to import the database schema

# /usr/local/bin/mysql -u cacti -p cacti < /usr/local/share/cacti/cacti.sql

Now add your details to the config script by editing it:

$database_type = "mysql";
$database_default = "cacti";
$database_hostname = "localhost";
$database_username = "cacti";
$database_password = "cacti";
$database_port = "3306";
$database_ssl = false;

Now create the cron job for cacti

crontab -u cacti -e
add:
==/==
*/5 * * * * /usr/local/bin/php /usr/local/share/cacti/poller.php > /dev/null 2>&1
==/==

Now we just need to set up the Apache config

ee /usr/local/etc/apache22/Includes/httpd-local.conf
==/==
<Directory /usr/local/share/cacti>
AllowOverride None
Order Allow,deny
Allow from all
</Directory>
Alias /cacti /usr/local/share/cacti/
==/==

/usr/local/etc/rc.d/apache22 restart

At this point you would expect everything to ‘just work’, however it didn’t! The first this was to add index.php as a default document into the apache config file. Here I have added index.php into my /usr/local/etc/apache22/httpd.conf file:

#
# DirectoryIndex: sets the file that Apache will serve if a directory
# is requested.
#
<IfModule dir_module>
DirectoryIndex index.php index.html
</IfModule>

The next set of errors was all due to php not having the timezone set correctly. This was resolved by first creating a php.ini file and then modifying it to have a timezone set:

cp /usr/local/etc/php.ini-production /usr/local/etc/php.ini
ee /usr/local/etc/php.ini
==/modify/==
[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
date.timezone = Europe/London
==/==

Now it all works – as far as you can browse to the site http://host_ip_address/cacti and from there the install wizard starts.

This entry was posted in FreeBSD Administration. Bookmark the permalink.

Leave a Reply