ZoneMinder – adding USB camera

Goal is to attach a USB camera to UbuntuServer and then configure for ZoneMinder

LESSONS LEARNED:
-Really look at installation docs carefully
-I needed to use the default zmpass login
-I needed to make sure of:
ScriptAlias matches PATH_ZMS.
ScriptAlias /zm/cgi-bin /usr/lib/zoneminder/cgi-bin
From console go to Options->Path and make sure PATH_ZMS is set to /zm/cgi-bin/nph-zms.-
-I didn’t quite read it correctly, and thought I should enter /zoneminder
-There is a slight delay when loading the image before it comes on screen
-Overall – key is to review and understand ALL installer documentation before actually beginnning.

-Attached my Logitech Orb Camera to USB port on server
-To see a list of your USB devices (the vendor and device ID’s), run:
lsusb
Note: Came back with — Bus 001 Device 011: ID 046d:0994 Logitech, Inc. QuickCam Orbit/Sphere AF
Note: This is a good start, as it appears to have auto-loaded the USB device

-I think first step is to run some program called Cheese to confirm camera is functioning
https://help.ubuntu.com/community/Webcam

sudo apt-get install cheese
Note: I believe it installed, but…

Note: When I run: cheese
Failed to connect to Mir: Failed to connect to server socket: No such file or directory
Unable to init server: Could not connect: Connection refused

** (cheese:26617): ERROR **: cheese-application.vala:86: Unable to initialize libcheese-gtk
Trace/breakpoint trap (core dumped)

I read someplace that if a user wants to access the webcam, they have to be in the video group
usermod – G video paul
Note: I don’t think this is quite the answer

When I go into Log within ZM, I see:
Failed to open video device /dev/video0: Permission denied

Checking security:
ls -al /dev/video (returns with)
crw-rw—- 1 root video 81, 0 Dec 17 18:16 /dev/video0

I remember seeing a message earlier, upon logging in, that said to restart server
sudo reboot

I think there is a rights issue. Within the log it says:
Failed to open video device /dev/video0: Permission denied

sudo chmod 777 /dev/video0
sudo a2enmod cgi (NOTE: Don’t think I needed to do this)
service zoneminder restart

Checked the log. Don’t see the rights issue, but I see:
Failed to set camera source 11: Invalid argument
Note: This could be because I set camera to what I thought was channel 11

Note: Getting close now, because the camera now has an orange light on it…

Now I’m seeing this in log:
Socket /var/run/zm/zms-327516s.sock does not exist. This file is created by zms, and since it does not exist, either zms did not run, or zms exited early. Please check your zms logs and ensure that CGI is enabled in apache and check that the PATH_ZMS is set correctly. Make sure that ZM is actually recording. If you are trying to view a live stream and the capture process (zmc) is not running then zms will exit. Please go to http://zoneminder.readthedocs.io/en/latest/faq.html#why-can-t-i-see-streamed-images-when-i-can-see-stills-in-the-zone-window-etc for more information.

Goal: enable CGI in Apache
Followed: https://code-maven.com/set-up-cgi-with-apache
cd /etc/apache2/mods-enabled
sudo ln -s ../mods-available/cgi.load (Note: Said something about already existing)
sudo service apache2 reload
Note: According to Log: Logi-USB-Orbit: 7000 – Capturing at 5.00 fps
Camera still on amber

Restarted server

Need to resolve this error, and also be logged in as Paul:
ERR Socket /var/run/zm/zms-770262s.sock does not exist. This file is created by zms, and since it does not exist, either zms did not run, or zms exited early. Please check your zms logs and ensure that CGI is enabled in apache and check that the PATH_ZMS is set correctly. Make sure that ZM is actually recording. If you are trying to view a live stream and the capture process (zmc) is not running then zms will exit. Please go to http://zoneminder.readthedocs.io/en/latest/faq.html#why-can-t-i-see-streamed-images-when-i-can-see-stills-in-the-zone-window-etc for more information.

1) Keep the default zone apache.conf without the ScriptAlias.

2) Stop both zoneminder and apache2
sudo service apache2 stop
sudo service zoneminder stop

2) Remove any stale sockets from /tmp/zm (default location):
sudo rm -vf /tmp/zm/*.*

3) sudo a2enmod cgi
NOTE: Got this error again:
1) Keep the default zone apache.conf without the ScriptAlias.

2) Stop both zoneminder and apache2
sudo service apache2 stop
sudo service zoneminder stop

2) Remove any stale sockets from /tmp/zm (default location):
sudo rm -vf /tmp/zm/*.*

3) sudo a2enmod cgi
Note: Got this error:
AH00558: apache2: Could not reliably determine the server’s fully qualified domain name, using 127.0.1.1. Set the ‘ServerName’ directive globally to suppress this message

Within /etc/hostname it has “ubuntusec” — this is legacy and I’ll keep it for now
https://askubuntu.com/questions/256013/apache-error-could-not-reliably-determine-the-servers-fully-qualified-domain-n

Within /etc/apache2 I created a folder called conf.d
Within /etc/apache2/conf.d I created a new file called fqdn with:
ServerName localhost

4) Start zoneminder
sudo service zoneminder start

5) Start apache2
sudo service apache2 start

I found out that the order was important for step 4 and 5, otherwise it doesn’t work.
4) Start zoneminder
sudo service zoneminder start

5) Start apache2
sudo service apache2 start

I found out that the order was important for step 4 and 5, otherwise it doesn’t work.

I’m getting close, but still have this error:
Socket /var/run/zm/zms-138038s.sock does not exist. This file is created by zms, and since it does not exist, either zms did not run, or zms exited early. Please check your zms logs and ensure that CGI is enabled in apache and check that the PATH_ZMS is set correctly. Make sure that ZM is actually recording. If you are trying to view a live stream and the capture process (zmc) is not running then zms will exit. Please go to http://zoneminder.readthedocs.io/en/latest/faq.html#why-can-t-i-see-streamed-images-when-i-can-see-stills-in-the-zone-window-etc for more information.

Zoneminder – installation tune-up

I think what happened is that I went through an easy install, and a bunch of things didn’t quite get installed or configured. Good thing is that the camera has an orange light, but I’m getting log errors and also not seeing the image within ZM.

I’m going to follow this wiki and do the various recommended configs:
https://wiki.zoneminder.com/Ubuntu_Server_16.04_64-bit_with_Zoneminder_1.29.0_the_easy_way

-I’m going to keep MySQL database for now, and hold off on MariaDB

-I’m sure I did the my.cnf setting, but I confirmed:
nano /etc/mysql/my.cnf
In the [mysqld] section add the following:
sql_mode = NO_ENGINE_SUBSTITUTION

-Optional: A tool that you may want to install is mysqltuner. This is handy to see what database parameters need to be adjusted as your ZM system builds up events.
Note: Will come back to this later, when I’ve got camera working
apt-get install mysqltuner
Once installed, run mysqltuner from a command prompt as root (sudo). Review recommended changes. Edit the configuration file (my.cnf) and make the recommended changes. Stop zoneminder, restart the database server then start zoneminder.

-Create Zoneminder database in MySQL (Note: this also creates the default Zoneminder user and permissions in MySQL)
mysql -uroot -p < /usr/share/zoneminder/db/zm_create.sql Note: I didn't do this command because I already see the file zm_create.sql mysql -uroot -p -e "grant all on zm.* to 'zmuser'@localhost identified by 'zmpass';" Note: I tried this but it didn't work when I entered root password. Not sure what this means. mysqladmin -uroot -p reload Note: Same error trying to login to root. Not sure what this is -Set permissions of /etc/zm/zm.conf to root:www-data 740 chmod 740 /etc/zm/zm.conf chown root:www-data /etc/zm/zm.conf adduser www-data video Note: Come back with: Adding user `www-data' to group `video' ... Adding user www-data to group video -Enable CGI, Zoneminder and rewrite configuration in Apache. Note: I think this is the issue I'm having, so see what happens... a2enmod cgi Note: Comes back with: AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message Module cgi already enabled NOTE: I'm going to hold off on any more changes, because in the log it says: Logi-USB-Orbit: 500000 - Capturing at 14.93 fps Checked the log again. Now I see this again Socket /var/run/zm/zms-014138s.sock does not exist. This document address several things -- easy install; iConnor PPA https://github.com/ZoneMinder/ZoneMinder/issues/1879 One should simply execute the following to enable zoneminder's apache config: sudo service apache2 stop sudo service zoneminder stop a2enconf zoneminder Note: Comes back with Conf zoneminder already enabled http://zoneminder.readthedocs.io/en/latest/faq.html#why-can-t-i-see-streamed-images-when-i-can-see-stills-in-the-zone-window-etc Checking httpd.conf within /etc Enable CGI, Zoneminder and rewrite configuration in Apache. Open Zoneminder in a web browser (http://server-ip/zm). Click on Options - Paths Change PATH_ZMS to /zm/cgi-bin/nph-zms (Caution: make sure you enter only /zm/cgi-bin/nph-zms with no space at the end or your video will not work!) Note: PATH_ZMS was going to /cgi-bin/nph-zms I was tinkering inside /usr/lib and see a cgi-lib folder which is empty Within /usr/lib there is a zoneminder folder and... Within /usr/lib/zoneminder is a freakin' cgi-bin folder... Within that there is nph-zms and zms The above documentation is slightly correct, but I'm going to go in Zoneminder, options and change to: /zoneminder/cgi-bin/nph-zms Did a: service apache2 restart service zoneminder restart Note: I think I may have addressed the cgi-bin location, but don't think zms is running Note: This is Ubuntu's doc on Apache -- https://help.ubuntu.com/lts/serverguide/httpd.html I noticed within Options, Path, PATH_ZMS, I had forgotten to add the leading / Note: Corrected that and did a: service zoneminder restart The /cgi-bin directory that contains the program zms and the symlink nph-zms. These are needed to see a live stream. The /cgi-bin needs to be declared or assigned an alias, as is done in Apache or Hiawatha in the configuration file. This also is the case with nginx. So I think that your issue involves the path to the /cgi-bin....which on my system which is at the moment Puppy Linux Tahr 6.0.6 (Ubuntu 14.04 binaries), lives at /usr/lib/zoneminder/cgi-bin and is aliased to http://your_server/cgi-bin. look at Options->Paths->Path_ZMS….does this path match the alias setup in your web servers config?
I definitely think your problem involves this issue in someway.

In my case, within /usr/lib/zoneminder/cgi-bin there are nph-zms (symlink) and zms (program)
Note: In all the boards I’ve seen they reference zm but mind is zoneminder

Within /var/log/apache2 is an error.log file
[cgi:error] [pid 3587] [client 192.168.1.4:58602] AH02811: script not found or unable to stat: /usr/lib/cgi-bin/nph-zms, referer: http://192.168.1.15/zm/in$

Well… that makes sense because the directory is empty. The cgi-bin files are within /usr/lib/zoneminder/cgi-bin

Went into: /etc/apache2/sites-available
nano default-ssl.conf and changed from:
/usr/lib/cgi-bin to:
/usr/lib/zoneminder/cgi-bin

Checked the error.log again
I think I fixed the cgi-bin path issue, but still have the socket issue:
[:error] [pid 6353] [client 192.168.1.4:62739] ERR [Socket /var/run/zm/zms-028757s.sock does not exist. This file is created by zms, and since it does not exist

That happens when your Apache ScriptAlias directive is configured incorrectly or overlaps with another ScriptAlias (like the one that ships with your httpd.conf).

Went back into 000-default.conf and entered:

SSLOptions +StdEnvVars


SSLOptions +StdEnvVars

I read someplace to add this to the 000-default.conf file
ScriptAlias /cgi-bin/ /usr/lib/zoneminder/cgi-bin/

Options +ExecCGI
AddHandler cgi-script .cgi .pl
Options FollowSymLinks
Require all granted

service apache2 start
service zoneminder start
Note: Orange light comes on in camera

sudo a2enmod cgi
Comes back with:
[alias:warn] [pid 7584] AH00671: The ScriptAlias directive in /etc/apache2/sites-enabled/000-default.conf at line 34 will probably never match because it overlaps an earlier ScriptAlias.

Back to 000-default.conf
Reviewing this site – where it all began…
https://code-maven.com/set-up-cgi-with-apache

I looked around the /etc/apache2 directory, which is the standard place to find the configuration files of Apache. I’ve found the /etc/apache2/conf-available/serve-cgi-bin.conf file that has a symbolic link from /etc/apache2/conf-enabled/serve-cgi-bin.conf. It has a section that maps the /cgi-bin path in the URLs to the /usr/lib/cgi-bin/ directory in the hard disk and enables CGI execution in this directory.

Within /etc/apache2/conf-available/serve-cgi-bin.conf I think the issue is that it’s pointing to:
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
Note: This explains the error I had regarding overlap. It’s also needing to be pointed to the zoneminder folder

Changed it to ScriptAlias /cgi-bin/ /usr/lib/zoneminder/cgi-bin/

sudo service apache2 restart
sudo a2enmod cgi

Still getting the overlap message. Maybe I don’t need the entry in 000-default, so I will remark it out

sudo a2enmod cgi
I think progress, because only msg about ServerName

sudo service apache2 start
sudo service zoneminder start

I think the answer is within this board posting, but I’m still not clear:
https://bugs.launchpad.net/ubuntu/+source/zoneminder/+bug/1159361

Hmmmn…. I checked out this site and looked carefully:
http://zoneminder.readthedocs.io/en/latest/installationguide/ubuntu.html#harder-way-build-package-from-source

/etc/apache2/conf-enabled/zoneminder.conf
# Remember to enable cgi mod (i.e. “a2enmod cgi”).
ScriptAlias /zm/cgi-bin “/usr/lib/zoneminder/cgi-bin”

Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
AllowOverride All
Require all granted

Issue is that I really need to be putting /zm/cgi-bin within PATH_ZMS is set to /zm/cgi-bin/nph-zms.

Just saw this:

Changed Default DB User
If you have changed your DB login/password from zmuser/zmpass, you need to update these values in zm.conf.

Edit zm.conf to change ZM_DB_USER and ZM_DB_PASS to the values you used.

I FREAKIN’ FIGURED IT OUT!!!!

I needed to create a zmuser (because that was a default account created).

Now I can see the real-time camera image within the browser. Cool!!!!

Now I can move on to something else.

Note: Color still on orange.

Zoneminder – understanding web-console

Logged in as – admin (Note: This is also how to logout by clicking on admin)
Options = bunch of tabs and settings
Log = used for logging; investigate if “red”
Events to month (columns) = core of ZM – when zones are triggered
Zones = useful for focusing in areas that you want to allow for triggering (eg motion)
Source = Type of camera (IP, USB) — useful for troubleshooting camera, if red
Function = How Zm records. Note: These are the variables:
Modect == record if a motion is detected,Record = always record 24×7, Mocord = always record PLUS detect motion, Monitor = just provide a live view but don’t record anytime, Nodect = Don’t record till an external entity via zmtrigger tells Zoneminder to (this is advanced usage).
Button to view a montage of various cameras, etc
Running = Running” text, ZoneMinder brings up a popup that allows you to define additional “states” (referred to as runstates). A runstate is essentially a snapshot that records the state of each monitor and you can switch between states easily.

Zoneminder – Authentication

To configure security:
Options, System
Settings before:
-OPT_USE_AUTH = UNCHECKED (to authenticate ZM users)
-AUTH_TYPE = builtin (what is used to auth ZM users)
-AUTH_RELAY = hashed (method used to relay auth info)
-AUTH_HASH_SECRET = “change me to something unique” (secret for encoding hashed auth info)
-AUTH_HASH_IPS = checked (Include IP address in the auth hash)

Settings after:
-OPT_USE_AUTH = checked
-AUTH_HASH_SECRET =
Note: Kept everything else as is
Note: Clicked refresh on ZM browser, and now presented with a username/password ==

Installing ZoneMinder on UbuntuServer – Enable and Start ZM

Enabling and Starting ZoneMinder:

systemctl enable zoneminder
Note: It came back with:
Synchronizing state of zoneminder.service with SysV init with /lib/systemd/systemd-sysv-install…
Executing /lib/systemd/systemd-sysv-install enable zoneminder

systemctl start zoneminder
Note: It didn’t come back with anything re: prompts. Probably OK, though.

Edit TimeZone
nano /etc/php/7.0/apache2/php.ini

Search for [Date] (Ctrl + w then type Date and press Enter) and change date.timezone for your time zone, see [this](http://php.net/manual/en/timezones.php). Don’t forget to remove the ; from in front of date.timezone

Configured so it looks like this:
[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
date.timezone = America/Los_Angeles

Reload Apache Service
systemctl reload apache2

Making sure ZM is running:
http://192.168.1.15/zm
Note: Freakin’ awesome!!! I have a console to work with

Optional API Check

http://192.168.1.15/zm/api/host/getVersion.json

Note: Came back with:
version “1.30.4”
apiversion “1.0”

Note: Looks all good right now!!!

NOTE: At the end of the installation, there was a comment about:

PPA install may need some tweaking of ZMS_PATH in ZoneMinder options.
http://zoneminder.readthedocs.io/en/latest/installationguide/ubuntu.html#socket-sendto-or-no-live-streaming
Note: I didn’t do anything, but may need to come back to this after installing a camera.

Compilation of interests, thoughts and musings…