Zoneminder on FreeNAS

Status
Not open for further replies.

thewiep

Dabbler
Joined
Jun 12, 2011
Messages
31
There is a PC-BSD PBI available for ZoneMinder here:
http://pbibuild64.pcbsd.org/

After using Plugin - Upload I get:
plugins/ZoneMinder/4/_s/status: HTTP Error 502: Bad Gateway

There are instructions on installing it in FreeNAS here:
http://doc.freenas.org/index.php/Installing_a_PC-BSD_PBI

But sadly there is also a text in bold which says DOESN'T WORK IN 9.2.0

after testing it anyway there is an error in the first step:
pkg: No packages matching 'pcbsd-utils' available in the repositories

I also found a bugreport that might be related:
https://bugs.freenas.org/issues/2460

I anyone has any tips, they are appreciated as I would really like to get ZoneMinder running :)
 

guglez

Explorer
Joined
Feb 21, 2014
Messages
56
Does anyone had a chance to install zoneminder on freenas successfuly?

Отправлено с моего GT-N7100 через Tapatalk
 

SinDeus

Explorer
Joined
Sep 3, 2013
Messages
65
Hello all,

After days of struggling, I finally had ZoneMinder run on my FreeNAS box. Yay!
Everything works, except for viewing live streams & event videos - I get an error 500 and the Cambozola Java applet fails. I am still investigating that point.

I used the ZoneMinder port (version 1.25.0), installed it within a PHP/MySQL (MariaDB actually)/Apache (works with NGinx too) jail, fixed a hell of permissions and parameters, and voilà. It successfully connects to my DLink DCS 5020L IP camera, detects and stores events, though I am currently stuck at viewing videos.

Do not hesitate to ask questions, in the meantime I will try to write a small guide to set up a ZoneMinder installation on FreeNAS.
 

9C1 Newbee

Patron
Joined
Oct 9, 2012
Messages
485
I hope you get this ironed out. I could sure use this.
 

SinDeus

Explorer
Joined
Sep 3, 2013
Messages
65
Great news fellas!

I've got it fully working \o/
I'll post a guide today if I get enough time.
 

SinDeus

Explorer
Joined
Sep 3, 2013
Messages
65
OK, let's get going. Here is how to install ZoneMinder in a FreeNAS jail and get it working:

1. Create a jail with a web server

Create a new portjail (or use an existing one) and connect to it in CLI. Reminder: open the terminal and type:
Code:
[me@freenas] /# jls
   JID  IP Address      Hostname                      Path
     1  -               couchpotato_1                 /mnt/YOUR_POOL/jails/couchpotato_1
     2  -               customplugin_1                /mnt/YOUR_POOL/jails/customplugin_1
     3  -               sickbeard_1                   /mnt/YOUR_POOL/jails/sickbeard_1
     4  -               sickbeard_2                   /mnt/YOUR_POOL/jails/sickbeard_2
     5  -               transmission_1                /mnt/YOUR_POOL/jails/transmission_1
     6  -               owncloud_1                    /mnt/YOUR_POOL/jails/owncloud_1
    10  -               webserver                     /mnt/YOUR_POOL/jails/webserver
[me@freenas] /# jexec 10 tcsh
root@webserver:/ #

My jail here is named "webserver", and has the ID 10.
Then, update the ports collection by typing:
Code:
root@webserver:/ # portsnap fetch update

We are now ready to install Apache, MySQL, and PHP:
  • Apache
    Code:
    root@webserver:/ # cd /usr/ports/www/apache24/
    root@webserver:/usr/ports/www/apache24 # make install clean
    • Be sure to include the CGI module when configuring the installation.
  • MySQL
    Code:
    root@webserver:/usr/ports/www/apache24 # cd /usr/ports/databases/mysql55-server/
    root@webserver:/usr/ports/databases/mysql55-server # make install clean
    • I chose to install MariaDB, a MySQL fork, it should be exactly similar for both.
  • PHP
    Code:
    root@webserver:/usr/ports/databases/mysql55-server # cd /usr/ports/lang/php55
    root@webserver:/usr/ports/lang/php55 # make install clean
    • You will also need the MySQL and Socket modules, add them via another port:
      Code:
      root@webserver:/usr/ports/lang/php55 # cd /usr/ports/lang/php55-extensions
      root@webserver:/usr/ports/lang/php55-extensions # make install clean

      You will have to explicitly select them in the configuration box.
    • There is one last thing to install: the PHP module for Apache.
      Code:
      root@webserver:/usr/ports/lang/php55-extensions # cd /usr/ports/www/mod_php5
      root@webserver:/usr/ports/www/mod_php5 # make install clean
If you forgot to include the modules, or if your existing web server doesn't have these modules installed, you can do:
Code:
make config
make reinstall


2. Install ZoneMinder

We are installing the ports version:
Code:
root@webserver:/usr/ports/lang/php55 # cd /usr/ports/multimedia/zoneminder/
root@webserver:/usr/ports/multimedia/zoneminder # make install

Do not clean yet!
Before that, we have to create a database and a user for the zoneminder application to work. Here we go:
Code:
root@webserver:/usr/ports/multimedia/zoneminder # mysql -u root -p
Enter password: [usually blank]
mysql> create database zm;
mysql> grant all on zm.* to user 'zmuser'@'localhost' identified by 'zmpass';
mysql> flush privileges;
mysql> exit;
root@webserver:/usr/ports/multimedia/zoneminder # mysql -u root -p zm < work/ZoneMinder-1.25.0/db/zm_create.sql

You can change the default database name (zm), the user (zmuser) and its password (zmpass) as you like, but be sure to change them in the file /usr/local/etc/zm.conf as well (at the end of the file).
Since we are meddling with ZoneMinder configuration, let's tweak some files to prevent some errors:
  • In the file /usr/local/www/zoneminder/data/skins/classic/views/monitorprobe.php, switch "arp -a" to "/usr/sbin/arp -a".
  • Run the following commands:
    Code:
    root@webserver:/ # chown -R www:www /usr/local/www/zoneminder/data/events/
    root@webserver:/ # chown -R www:www /usr/local/www/zoneminder/data/images/

3. Enable services

Before we can start all our services, we just need to add them in the /etc/rc.conf file. Add the following lines:
Code:
apache24_enable="YES"
mysql_enable="YES"
zoneminder_enable="YES"


4. Register ZoneMinder in Apache

We have now to configure Apache so we can access the ZoneMinder web GUI:
Code:
root@webserver:/ # vi /usr/local/etc/apache24/httpd.conf

Add the following lines (I use the vi text editor, feel free to use the one you're the most comfortable with):
Code:
<FilesMatch "\.php$">
        SetHandler application/x-httpd-php
</FilesMatch>
<FilesMatch "\.phps$">
        SetHandler application/x-httpd-php-source
</FilesMatch>

Alias /zoneminder /usr/local/www/zoneminder/data

<Directory /usr/local/www/zoneminder/data>
        AllowOverride All
        Require all granted
        php_flag register_globals off
        Options Indexes FollowSymlinks
        <IfModule mod_dir.c>
                DirectoryIndex index.php
        </IfModule>
</Directory>

ScriptAlias /cgi-bin "/usr/local/www/zoneminder/cgi-bin"

<Directory "/usr/local/www/zoneminder/cgi-bin">
        Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
        AllowOverride All
        Require all granted
        php_value short_open_tag 1
</Directory>


Be sure to comment out any other ScriptAlias declaration in this file!

5. Set up system variables

Let's go back to the FreeNAS GUI! There, you will have to add two sysctl values, in order to increase the shared memory:
  • kern.ipc.shmmax → 2457600001
  • kern.ipc.shmall → 33554432
These values are intended to be high, but are indeed calculated according to your own camera capabilities (see https://forums.freebsd.org/viewtopic.php?&t=2323). You will end up having this:

index.php


But that's not quite it yet. The jail will have to have access to the SysVIPC service (inter-process communication for our shared memory), so open up the host console and locate the file:
Code:
[me@freenas] /# vi /mnt/YOUR_POOL/jails/.webserver.meta/jail-flags
.webserver.meta is a directory associated with my webserver jail. Be sure to look for your own jail with its proper name.
This file should normally contain the following line:
Code:
allow.raw_sockets=true
You have to had this line to allow the SysVIPC access:
Code:
allow.sysvipc=1


Restart your jail.

6. Start

Take a deep breath. Here we go:
Code:
root@webserver:/ # service apache24 start
root@webserver:/ # service mysql start
root@webserver:/ # service zoneminder start

Point your browser to your:jail:ip/zoneminder and you should be able to access the ZoneMinder web GUI, see that the service is running, and set up a new monitor. The ZoneMinder wiki is your source for information now.

7. Feedback

If anything went wrong, if I missed anything, or if you think this guide is not that clear: please feel free to point it out, so I can update it accordingly. Thank you for reading it!

Sources & kudos
 

Attachments

  • freenas - sysctl.PNG
    freenas - sysctl.PNG
    67 KB · Views: 1,868
Last edited:

9C1 Newbee

Patron
Joined
Oct 9, 2012
Messages
485
When I get some time (this weekend I hope) I will try this out. I am an uber noob so even following your instructions will end up being a learning curve. But this will be sweet when I get it running.
 

SinDeus

Explorer
Joined
Sep 3, 2013
Messages
65
If you have any question, do not hesitate to ask them here.
 

SinDeus

Explorer
Joined
Sep 3, 2013
Messages
65
@nvader Waiting for your feedback then ;)
 

nvader

Explorer
Joined
Dec 20, 2012
Messages
53
@nvader Waiting for your feedback then ;)
I'm struggling to get this set up.
I installed a fresh ports jail and just about ever step of the way, i get a "stop" .......
*** [install] Error code 1
I was able to finally get webmin installed and through that apache. mysql was a no go. i tried all the ports and 5.1 seemed to work okay. PHP installed. then i moved on to zone minder
but getting stops and errors along the way.
I may scrap everything and start over.
 

SinDeus

Explorer
Joined
Sep 3, 2013
Messages
65
Can you post the errors that occur? Like, the few lines just before *** [install] Error code 1.
 

nvader

Explorer
Joined
Dec 20, 2012
Messages
53
Can you post the errors that occur? Like, the few lines just before *** [install] Error code 1.

Here is what i get.

===> curl-7.38.0_1 depends on package: nghttp2>=0.6.0 - not found
===> Verifying install for nghttp2>=0.6.0 in /usr/ports/www/nghttp2
===> nghttp2-0.6.1 nghttp2 requires OpenSSL 1.0.1+.
*** [install] Error code 1

Stop in /usr/ports/www/nghttp2.
*** [build-depends] Error code 1

Stop in /usr/ports/ftp/curl.
*** [install] Error code 1

Stop in /usr/ports/ftp/curl.
*** [lib-depends] Error code 1

Stop in /usr/ports/devel/cmake.
*** [install] Error code 1

Stop in /usr/ports/devel/cmake.
*** [build-depends] Error code 1

Stop in /usr/ports/graphics/png.
*** [install] Error code 1

Stop in /usr/ports/graphics/png.
*** [lib-depends] Error code 1

Stop in /usr/ports/graphics/netpbm.
*** [install] Error code 1

Stop in /usr/ports/graphics/netpbm.
*** [lib-depends] Error code 1

Stop in /usr/ports/multimedia/zoneminder.
root@Ports:/usr/ports/multimedia/zoneminder #

however, I installed openssl and still get the same issue, even after a restart.


===> openssl-1.0.1_15 is already installed
 

SinDeus

Explorer
Joined
Sep 3, 2013
Messages
65
You could try to disable http2 in the cURL port. To do so, type:
Code:
cd /usr/ports/ftp/curl
make config
...
[ uncheck http2 in the configuration window, by pressing space on the specific line, then enter ]
...
make reinstall
 

dunkyboy

Cadet
Joined
Jul 12, 2014
Messages
3
Great tutorial.
A few things were different for me.

Instead of:
Code:
root@webserver:/ # portsnap fetch update

I needed to also extract ports, otherwise the ports directory does not even exist with a new install.
Code:
root@webserver:/ # portsnap fetch extract update


I also had to uninstall and reinstall my ports-mgmt/pkg.

I was unable to find options "include the MySQL and Socket modules when configuring the installation."

So, after installation and entering password I got:
Code:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)


So, not sure where to go from here.
 
Last edited:

SinDeus

Explorer
Joined
Sep 3, 2013
Messages
65
I was unable to find options "include the MySQL and Socket modules when configuring the installation."

My bad, they can be turned on in the php55-extensions port. I'll update the guide accordingly.

Regarding your error, are you sure your MySQL server is up? Try running:
Code:
service mysql-server start


Let me know.
 

dunkyboy

Cadet
Joined
Jul 12, 2014
Messages
3
Wow, thanks for your quick response.

OK, all good until starting services, then apache does not start:

Following error:
Code:
Performing sanity check on apache24 configuration:
AH00526: Syntax error on line 365 of /usr/local/etc/apache24/httpd.conf:
Invalid command 'php_value', perhaps misspelled or defined by a module not included in the server configuration
Starting apache24.
AH00526: Syntax error on line 365 of /usr/local/etc/apache24/httpd.conf:
Invalid command 'php_value', perhaps misspelled or defined by a module not included in the server configuration
/usr/local/etc/rc.d/apache24: WARNING: failed to start apache24

Also, couldn't start MySQL - but maybe if we could start with Apache.
 

SinDeus

Explorer
Joined
Sep 3, 2013
Messages
65
There seems to be an error on line 365 of your httpd.conf (Apache configuration file).
Can you post this line (located in /usr/local/etc/apache24/httpd.conf)? Along with some of the surrounding lines, to have some context.

Edit: After re-reading your post, I thought that maybe your Apache doesn't include the PHP module. Can you find a line that states
Code:
LoadModule php5_module        libexec/apache24/libphp5.so
in your httpd.conf? If not, try adding it. If it is preceded by a #, remove it.
 
Status
Not open for further replies.
Top