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:
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:
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