Friday, February 15, 2013

Getting Zoneminder running on FreeBSD

I noticed FreeBSD has a zoneminder port, which is great. My application is only for IP cameras, I haven't tested a bttv card, and my experiments with these cards on Linux leave much to be desired. I seem to be getting much better results out of $70 IP cams than I was getting from a BTTV card (unknown brand, found it in the stock room).

HP ML110g7 box, 10GB ram, 1 3TB disk. FreeBSD 9.1-RELEASE. Today's portsnap.

Step 1:
Recompile your kernel, increasing SHMMAX and SHMMNI (I couldn't get Mary Poppins out of my head after that...). I used some very large values here, and this is probably highly tunable:

options SHMMAX=2457600001
options SHMMAXPGS=60000
options SHMMNI=4096

I cribbed the values from here:
and made up the value for SHMMNI :)

Step 2:
Install the following ports/packages and their dependencies. I used portmaster, since it front-loads all of the config dialogs. I noticed some oddities running portmaster directly at zoneminder on a clean system, so I recommend this approach.


Step 2:
If you are impatient, you will have tried and failed to start zoneminder.
The problem of course is the database has not been configured.
This part took a while to figure out, because the .sql script in the zm sources is designed to have substitution done during configuration.

Here's the trick
cd /usr/ports/multimedia/zoneminder
make deinstall clean
make install
mysql -u root < ./work/ZoneMinder-1.25.0/db/
mysql -u root
mysql> grant all on zm.* to user 'zmuser'@'localhost' identified by 'zmpass'; 
mysql> flush privileges;
mysql> exit

#NOTE: you can change the db pass later, edit /usr/local/etc/zm.conf and change it in mysql as well

cp /usr/local/etc/zm.conf.example /usr/local/etc/zm.conf

Step 3:
The next step is configuring apache to serve zoneminder out of the default host. Obviously you can do this with mod alias as well, I didn't need to do it that way. We're going to substitute the default paths in http.conf for zoneminder's and then add mime types for PHP.

sed -ie 's/\/www\/apache22\//\/www\/zoneminder\//g' \ /usr/local/etc/apache22/httpd.conf
sed -ie 's/index.html/index.php/g' /usr/local/etc/apache22/httpd.conf
vi /usr/local/etc/httpd.conf

#NOTE: insert 
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
into the MIME section

ln -s /usr/local/etc/php.ini-production /usr/local/etc/php.ini
vi /usr/local/etc/php.ini

#NOTE: set your timezone or be greated by uncountable errors in the zm interface. Search for timezone, uncomment that line and set it to a valid PHP timezone. Mine was "America/Los_Angeles"

Step 4:

Add the following to /etc/rc.conf to get it to start at boot


Then reboot while praying.

Hope that helps, at least it worked for me.


  1. Thanks for the excellent guide. I'm glad someone documented the kernel changes required. (And LOL at your Chim Chim-e-ry joke).

    Are you running on baremetal or virtualized by chance? If virtualized, have you found any tweaks to maximize IO for something like Zoneminder that's swapping thousands of tiny JPEGs in and out of disk?

  2. I'm just running a handful of IP cams on cheapo HP ML series boxes baremetal, with ZFS as the file storage. Performance is more than adequate for my purposes anyway.

    If I was doing what you are doing, I'd want to have a really expensive RAID card with a BBU and tons of cache and a great UPS. Basically all the random IO needs to be aggregated and organized before it hits spindles. Or a big fast SAN with 10G if your volume of data is high. In either case, I'd have two arrays and two hosts, one that just ran the database (MySQL has different IO requirements than ZoneMinder) and another just running zoneminder.

    Tune the filesystem and storage for each workload on each host. Also, lots of RAM is good for both UFS and ZFS. MySQL has some pickyness with ZFS, and stuff like noatime and async can have applications in UFS2 land (turn off softupdates journaling and use geom_journal with log, trust me!). For ZFS, you can turn of atime, and you can disable the ZIL, use an SSD log device, tune the transaction group commit sizes, a lot more than I can remember or explain here.

    In my experience most virtualization environments are bottlenecked by the bandwidth to/from storage and often by the actual virtual IO drivers...of course your mileage may vary!

  3. so I am going to give this a try on a box running freeNAS 9.1.1 (notfreeBSD), fingers crossed it works however I dont expect much as I am not willing to re-compile the my kernel.

  4. Dang! Her I just shelled out for Blue Iris to run on my WHS2011 box. Good thing I'm building a new BSD box to replace my old workhorse. Zoneminder will be incorporated in that build to see what it does with my 6 IP cam's. (HP N40L microserver)
    Thanks for the detailed steps...

  5. In step 3 when I run the command
    sed -ie 's/\/www\/apache22\//\/www\/zoneminder\//g' /usr/local/etc/apache22/httpd.conf

    I recieve the message
    sed: /usr/local/etc/apache22/httpd.conf: No such file or directory

    the file /usr/local/etc/apache22/httpd.conf does in fact exist, any thoughts?

  6. Thanks for this article. I'm a Linux guy, and found this recipe enough to get ZM installed on my FreeNas box in a portjail.

  7. I've got everything running..I'm lost as how to add monitors.

    I have a brooktree 4 channel card, loaded kernel modules, tried replacing /dev/video with /dev/bktr0 that didn't work, so I did a little digging and found webcamd (recently switched to FreeBSD) tried webcamd -d devicename that didnt work too...

    Any ideas ?