====== ZoneMinder on FreeBSD 15: Technical Install Guide ====== This guide covers installing ZoneMinder on FreeBSD 15 with: * A remote MySQL/MariaDB server (''%%dbserver%%'') * NFS storage on a ZFS dataset (''%%nfsserver%%'') Assumptions: - You have root or sudo access on all systems - Substitute your preferred editor for ''%%edit%%'' in commands ===== 1. Prerequisites & Initial Setup ===== ==== 1.1 Database Server: Create ZoneMinder Database ==== CREATE DATABASE zm; CREATE USER 'zmuser'@'192.168.1.%' IDENTIFIED BY 'zmpass'; GRANT ALL PRIVILEGES ON zm.* TO 'zmuser'@'192.168.1.%'; FLUSH PRIVILEGES; > Adjust ''%%192.168.1%%'' to your subnet as needed. ==== 1.2 NFS Server: Create Dataset & Export ==== Create and export the dataset: zfs create pool/zoneminder zfs set quota=500G atime=off pool/zoneminder echo '/pool/zoneminder -alldirs -maproot=root' >> /etc/exports service mountd reload ===== 2. ZoneMinder Server: Preparation ===== ==== 2.1 Test Database Connection ==== mysql -h dbserver -u zmuser -p zm exit; ==== 2.2 Test NFS Mount ==== mount -t nfs nfsserver:/pool/zoneminder /mnt ls /mnt umount /mnt ==== 2.3 (Optional) Set up /tmp as Ramdisk ==== echo 'tmpfs /tmp tmpfs rw,nosuid,mode=1777 0 0' >> /etc/fstab rm -fR /tmp/* rm -fR /tmp/.* mount /tmp reboot # only if needed ===== 3. Install ZoneMinder & Dependencies ===== pkg install zoneminder-php85 nginx fcgiwrap ==== 3.1 Set Up Database and Storage ==== # initialize zm database mysql -h dbserver -u zmuser -p zm < /usr/local/share/zoneminder/db/zm_create.sql # move data to NFS mount nfsserver:/pool/zoneminder /mnt mv /var/db/zoneminder/* /mnt/ # expect errors as not all permissions match on NFS umount /mnt # configure NFS mount echo 'nfsserver:/pool/zoneminder /var/db/zoneminder nfs rw,soft 0 0' >> /etc/fstab mount /var/db/zoneminder chown -fR www:www /var/db/zoneminder ===== 4. Configure Services ===== In the following, I tried to set up a copy/paste and also backing up files before changing them. ==== 4.1 nginx ==== cd /usr/local/etc/nginx mv nginx.conf nginx.conf.save edit nginx.conf Paste in: worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { listen 80; root /usr/local/www/zoneminder; index index.php; gzip off; location /cgi-bin/nph-zms { include fastcgi_params; fastcgi_param SCRIPT_FILENAME $request_filename; fastcgi_pass unix:/var/run/fcgiwrap/fcgiwrap.sock; } location /zm/cache { alias /var/cache/zoneminder; } location /zm { alias /usr/local/www/zoneminder; location ~ \.php$ { if (!-f $request_filename) { return 404; } include fastcgi_params; fastcgi_param SCRIPT_FILENAME $request_filename; fastcgi_index index.php; fastcgi_pass unix:/var/run/php-fpm.sock; } location ~ \.(jpg|jpeg|gif|png|ico)$ { access_log off; expires 33d; } location /zm/api/ { alias /usr/local/www/zoneminder; rewrite ^/zm/api(.+)$ /zm/api/app/webroot/index.php?p=$1 last; } } } } ==== 4.2 php-fpm ==== cd /usr/local/etc/php-fpm.d/ mv www.conf www.conf.save edit /usr/local/etc/php-fpm.d/www.conf Paste in (change time zone if needed): [www] user = www group = www env[PATH] = /usr/local/bin:/usr/bin:/bin pm = dynamic pm.max_children = 5 pm.start_servers = 2 pm.min_spare_servers = 1 pm.max_spare_servers = 3 php_admin_value[date.timezone] = America/Chicago listen.owner = www listen.group = www listen = /var/run/php-fpm.sock ==== 4.3 ZoneMinder DB Credentials ==== Create ''%%/usr/local/etc/zoneminder/03-database.conf%%'' (do not edit ''%%zm.conf%%''): edit /usr/local/etc/zoneminder/03-database.conf Paste in: ZM_DB_TYPE=mysql ZM_DB_HOST=dbserver ZM_DB_NAME=zm ZM_DB_USER=zmuser ZM_DB_PASS=zmpass ===== 5. Enable & Start Services ===== Do each service in turn, troubleshooting if it fails to start ==== 5.1 nginx ==== sysrc nginx_enable="YES" service nginx start ==== 5.2 fcgiwrap ==== sysrc fcgiwrap_enable="YES" sysrc fcgiwrap_user="www" sysrc fcgiwrap_socket_owner="www" sysrc fcgiwrap_flags="-c 4" service fcgiwrap start ==== 5.3 php-fpm ==== echo 'date.timezone = "America/Chicago"' > /usr/local/etc/php/timezone sysrc php_fpm_enable="YES" service php_fpm start ==== 5.4 zoneminder ==== sysrc zoneminder_enable="YES" service zoneminder start ===== 6. Verification ===== Access ZoneMinder at: http://servername/zm **Recommendation:** Reboot and verify all services start automatically.