summaryrefslogtreecommitdiff
path: root/multimedia/zoneminder/files/pkg-message.in
blob: 6599d214cc40786d173f4ceabfe42792cf8e80d5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
[
{ type: install
  message: <<EOM
ZoneMinder requires a MySQL (or MySQL forks) database backend and 
a http server, capable to execute PHP and CGI scripts.

To simplify things, we assume, that you use MySQL and NGINX on 
the same server.

1. Preliminary steps

1.1 Install databases/mysql57-server or newer
	You may choose your favourite method - ports or packages here. 

	ZoneMinder use very simple queries, however it tends to write to 
	the database quite a lot depending on your capture mode and number 
	of cameras. So tweak your MySQL instance accordantly

	Now, enable and start MySQL
		sysrc mysql_server_enable="YES"
		service mysql-server start

1.2 Install www/nginx 
	We provide an example for an HTTP install, however, you should use 
	HTTPS if you plan to expose your installation to the public. There 
	are plenty guides how to do it and security/letsencrypt.sh is a 
	good way to get a valid SSL certificate. Probably, your installation
	will be behind reverse proxy, so this example should work for you.

	Please, notive the following issues with ZM:

	- web interface has several hardcoded /zm in url generation, so it is
		mandatory to serve your installtion from /zm subfolder
	- if behind reverse proxy, HTTP_X_FORWARDED_PROTO must be supplied or link
		generation will use http://

	Your server block should include the following:

	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;
			}
		}
	}

	Enable and start NGINX
		sysrc nginx_enable="YES"
		service nginx start

1.3 Install www/fcgiwrap 
	As NGINX lacks it's own CGI wrapper, we need external one. Please 
	note that ZoneMinder's montage page use simultaneous access to all 
	cameras, so you need to use at least as many fcgiwrap workers as 
	your number of cameras. The following example assumes you have 4.

	Enable and start FcgiWrap
		sysrc fcgiwrap_enable="YES"
		sysrc fcgiwrap_user="www"
		sysrc fcgiwrap_socket_owner="www"
		sysrc fcgiwrap_flags="-c 4"

1.4 PHP is installed as a dependency to ZoneMinder. However, you should 
	tweak some of it's settings.
	Edit /usr/local/etc/php-fpm.conf and set

		listen = /var/run/php-fpm.sock
		listen.owner = www
		listen.group = www
		env[PATH] = /usr/local/bin:/usr/bin:/bin

	If you want to set another path for the socket file, make sure you 
	change it in your NGINX config well. The env[PATH] needs to be set 
	to locate the zip utility as ZoneMinder's export functions rely on 
	exec(). Sorry, chroot folks. 

	PHP throws warning if date.timezone option is not set. The best place 
	to do it is to create new ini file in /usr/local/etc/php with overrides

		date.timezone = "UTC"

	Enable and start php-fpm
		sysrc php_fpm_enable="YES"
		service php-fpm start

1.5 ZoneMinder keeps the last 1-3 frames from monitors as cache when broadcasting 
        stream through zms. This can be a performance hog if 
	placed on spindle drive or add wear to SSD. The best practice is put it on 
	tmpfs. 	See https://www.freebsd.org/cgi/man.cgi?query=tmpfs for more 
	information.

	ZoneMinder will use /tmp for default. If you plan to change it, see 
	ZM_PATH_MAP setting.

	Edit /etc/fstab and add the following:

		tmpfs			/tmp		tmpfs	rw,nosuid,mode=01777	0	0

2. ZoneMinder installation

	Connect to MySQL under root and create zm user and populate database.

	mysql -u root -p
	
		CREATE DATABASE zm;
		GRANT ALL PRIVILEGES ON zm.* TO 'zmuser'@'localhost' IDENTIFIED BY 'zmpass';
		FLUSH PRIVILEGES;
		quit;
	
	mysql -u root -p zm < /usr/local/share/zoneminder/db/zm_create.sql
	
2.1 If you have chosen to change the ZoneMinder MySQL credentials to something
	other than zmuser/zmpass then you must now edit /usr/local/etc/zm.conf. Change
	ZM_DB_USER and ZM_DB_PASS to the values you created in the previous step.

	Enable and start ZoneMinder
		sysrc zoneminder_enable="YES"
		service zoneminder start
EOM
}
{ type: upgrade
  message: <<EOM
To perform an upgrade from any version:
 
1. Stop ZoneMinder
	service zoneminder stop

2. Upgrade database
	sudo -u www zmupdate.pl
	
3. Start ZoneMinder
	service zoneminder start

If you see error ERROR 1419 (HY000) during database update, set 
log_bin_trust_function_creators = 1 in runtime or in mysql server config;

For example, login as root and issue SET GLOBAL log_bin_trust_function_creators = 1;

Starting from version 1.36, ZM doesn't need too much tmpfs space. zmc process now
allocates memory as needed. tmpfs backed /tmp is still needed by zms to store 
1-3 images, so you shrink your tmpfs /tmp drasticallyi (if you followed installation
guide).
EOM
}
]