Zabbix on FreeBSD-9.2 and later

I don't know if there's a need for this page or not, but it took me longer to find out various bits and pieces than I felt it should. This is a quick run through on installing zabbix on a FreeBSD system, using MySQL as the database and Apache as the web server. It doesn't go into the configuration, it just takes you a bit past the point where you go to your server and get a Zabbix start page. We're making the assumption that you want to use MySQL-5.6 rather than 5.5 and apache24 rather than apache22.

This is the primary reason we're installing ports in the order given. Otherwise, for example, zabbix2-server pulls in mysql55-client.

I want to thank my friend Jeremiah, who read the first draft, and gave me several useful suggestions.

Start by installing apache, and mysql56-client.
cd /usr/ports/www/apache24
make install clean
cd /user/ports/databases/mysql56-client
make install clean

Install the zabbix server.
cd /usr/ports/net-mgmt/zabbix2-server
make install clean

Install mysql56-server.
cd /usr/ports/databases/mysql56-server
make install clean

Add mysql to /etc/rc.conf
mysql_enable="YES"

Start the mysql-server.
service mysql-server start

At this point, I use mysqladmin to give a password to the mysql server. If there are spaces in your password, use quotes. In this case, we'll use the password My Pass
mysqladmin -u root password "My Pass"
mysql -u root -p

Put in your password when requested, and you'll now be in mysql. For the sake of the example, we'll make the password for the zabbix database zabbixpass. I use the name zabbix for the database and the database user
create database zabbix;
grant all privileges on zabbix.* to zabbix@localhost identified by
'zabbixpass';
flush privileges;
\q

Now populate the database The zabbix2-server pkg-message which can be viewed after install, assuming you're using the new pkgng, with
pkg info -Dx zabbix2-server

suggests a slightly different method but you can use

cd /usr/local/share/zabbix2/server/database/mysql
cat schema.sql images.sql data.sql |mysql -u zabbix -p zabbix

and putting in the password when requested.

Configure the zabbix server.
cd /usr/local/etc/zabbix2
cp zabbix_server.conf_sample zabbix_server.conf

You only need to change 4 lines in the zabbix_server.conf file. Look for the lines, DBHost, DBName, DBUser, and DBPassword. We want our values to be
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=zabbixpass

Add to /etc/rc.conf
zabbix_server_enable="YES"

You should now be able to start the zabbix server with
service zabbix_server start

If this is being done in a jail, then you will also have to add a line to the jail host's /etc/rc.conf to let that particular jail use sysvipc. If the jail was named zabbixjail, the /etc/rc.conf line should read
jail_zabbixjail_parameters="allow.sysvipc=1"

In FreeBSD-10, which uses /etc/jail.conf instead of /etc/rc.conf entries, you will add this line to the zabbix jail's /etc/jail.conf stanza.
allow.sysvipc = 1

If that line is not already in the host's /etc/rc.conf you may have to restart the jail after adding it before the zabbix server will run.
service jail restart zabbixjail

You can check that it's running with
service zabbix_server status

Install the zabbix frontend.
cd /usr/ports/net-mgmt/zabbix2-frontend
make config

Just select the MYSQL MySQL database option, which should be selected by default.

It will pull in php5. Select the Build Apache module option.

Apache's default /usr/local/etc/apache24/httpd.conf points to a document root of /usr/local/www/apache24/data, so we'll copy the zabbix files there.
cd /usr/local/www/zabbix2
cp -a . /usr/local/www/apache24/data/

Next, let's edit /usr/local/etc/apache24/httpd.conf. Look for the line
DirectoryIndex index.html

Change it to index.php. You can leave the index.html in there if you like, just make sure that index.php is first, so that it reads
DirectoryIndex index.php index.html

Make sure that there is an uncommented line
LoadModule php5_module		libexec/apache/libphp5.so

Under that add
AddType application/x-httpd-php  .php
AddType application/x-httpd-php-source  .phps

Add a line to start apache to /etc/rc.conf
apache24_enable="YES"

Now configure php.ini
By default, FreeBSD-9.2's installation of php will create a /usr/local/etc/php.ini-development and /usr/local/etc/php.ini-production. You can use either one to create your desired /usr/local/etc/php.ini, for example
cd /usr/local/etc/
cp php.ini-production php.ini

In the php.ini file, you will make a few changes or zabbix will give errors. Change max_execution time from 30 to 300. Change max_input_time from 60 to 300, and change post_max_size from 8M to 16M. You will also need to put in your timezone. Find the line that reads
;date.timezone =

and put in the desired timezone. For example, I would use America/New_York
date.timezone= "America/New_York"

Start apache
service apache24 start

(If using apache22 or other version than 24, change the above command and rc.conf entry accordingly.)

Check that there is a /usr/local/www/apache24/data/conf directory. If not, create the directory.

If you open a browser and go to localhost, you should be at the Zabbix welcome screen and can begin setup. It may show root as the default user in step 3, change that to zabbix and give the zabbix password you assigned to the database. (In our example, zabbixpass). You will see a button to test the connection before going to the next screen.

In the next step, you can give the hostname and optionally name the installation. The default is localhost for the hostname and blank for the installation. The hostname used must be specified in /etc/hosts. That is, if I'm using the hostname zabbixjail, /etc/hosts must have an entry for it, either using the IP address or 127.0.0.1, for example
127.0.0.1	zabbixjail.example.com  zabbixjail

Otherwise, although the server will be working, the dashboard will have a message that server isn't running. So if changing it from the default of localhost, be sure that there is an entry in /etc/hosts.

In step 6, you may get a message, during the setup, that it was unable to create /usr/local/www/apache24/data/conf/zabbix.conf.php. It gives you a choice to download the file. This is sometimes fixed by downloading the file and putting it in /usr/local/www/apache24/data/conf. If that doesn't work, do a ls -l on the conf directory to note its ownership and permissions. Once that's done, change the permissions to 777 on the conf directory (or possibly change ownership to zabbix) and it should be able to create the file. When done, change permissions back to what they were.

You should get to a zabbix login screen. The username is admin and the password is zabbix. Once logged in, click on Administration, click on users, click on Admin and change the password.