Hard Way: Ubuntu 15, Compile ZoneMinder API from source - 3esmit/zmNinja GitHub Wiki
(Well, its really not hard. 13 steps and if you follow it exactly, you won't have problems)
If you already have ZM installed you will already have mysql server and other dependencies installed
Step 1: First make sure you have the needed tools
sudo apt-get update
sudo apt-get install cmake git
Step 2: Next up make sure you have all the dependencies
sudo apt-get install apache2 mysql-server php5 php5-mysql build-essential libmysqlclient-dev libssl-dev libbz2-dev libpcre3-dev libdbi-perl libarchive-zip-perl libdate-manip-perl libdevice-serialport-perl libmime-perl libpcre3 libwww-perl libdbd-mysql-perl libsys-mmap-perl yasm automake autoconf libjpeg8-dev libjpeg8 apache2 libapache2-mod-php5 php5-cli libphp-serialization-perl libgnutls-dev libjpeg8-dev libavcodec-dev libavformat-dev libswscale-dev libavutil-dev libv4l-dev libtool ffmpeg libnetpbm10-dev libavdevice-dev libmime-lite-perl dh-autoreconf dpatch policykit-1 libpolkit-gobject-1-dev libextutils-pkgconfig-perl libcurl3 libvlc-dev libcurl4-openssl-dev curl php5-gd
(you are asked for the mysql root password when installing mysql server - put in a password that you'd like).
Step 3: Download ZoneMinder source code and compile+install:
git clone https://github.com/ZoneMinder/ZoneMinder.git
cd ZoneMinder/
git submodule init
git submodule update
cmake .
make
sudo make install
Step 4: Now make sure your symlinks to events and images are set correctly:
sudo ./zmlinkcontent.sh
Step 5: Now lets make sure ZM has DB permissions to write to the DB:
mysql -uroot -p -e "grant select,insert,update,delete,create,alter,index,lock tables on zm.* to 'zmuser'@localhost identified by 'zmpass';"
Step 6: Now lets create the DB & its tables that ZM needs
mysql -uroot -p <db/zm_create.sql
Step 7: Now we need to make sure Ubuntu 15 is able to start/stop zoneminder via systemd:
sudo cp distros/ubuntu1504_cmake/zoneminder.service /lib/systemd/system
edit /lib/systemd/system/zoneminder.service file
- rename /usr/bin/zmpkg to /usr/local/bin/zmpkg everywhere
(The step above is needed because when you compile from source, it installs to /usr/local/instead of /usr/)
Step 8: Now lets make sure systemd recognizes this file
sudo systemctl daemon-reload
sudo systemctl enable zoneminder.service
Step 9: Now lets work on Zoneminder's apache configuration:
sudo cp distros/ubuntu1504_cmake/conf/apache2/zoneminder.conf /etc/apache2/conf-available/
sudo a2enconf zoneminder
sudo a2enmod cgi
sudo a2enmod rewrite
sudo service apache2 reload
Step 10: Edit /etc/apache2/conf-available/zoneminder.conf and change all occurrences of:
- /usr/lib/zoneminder/cgi-bin to /usr/local/libexec/zoneminder/cgi-bin
- /usr/share/zoneminder to /usr/local/share/zoneminder
After editing your /etc/apache2/conf-available/zoneminder.conf should look like:
ScriptAlias /zm/cgi-bin "/usr/local/libexec/zoneminder/cgi-bin"
<Directory "/usr/local/libexec/zoneminder/cgi-bin">
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
AllowOverride All
Require all granted
</Directory>
Alias /zm /usr/local/share/zoneminder/www
<Directory /usr/local/share/zoneminder/www>
php_flag register_globals off
Options Indexes FollowSymLinks
<IfModule mod_dir.c>
DirectoryIndex index.php
</IfModule>
</Directory>
<Directory /usr/local/share/zoneminder/www/api>
AllowOverride All
</Directory>
Step 11: Now lets make sure ZM can read/write to the zoneminder directory:
sudo chown -R www-data:www-data /usr/local/share/zoneminder/
Step 12: Edit Timezone in PHP
vi /etc/php5/apache2/php.ini Look for [Date] and inside it you will see a date.timezone that is commented. remove the comment and specific your timezone. Please make sure the timezone is valid (see this)
In my case:
date.timezone = America/New_York
Step 13: Finally, lets make a config change to apache (needed for htaccess overrides to work for APIs) Edit /etc/apache2/apache2.conf and add this:
<Directory /usr/local/share>
AllowOverride All
Require all granted
</Directory>
Restart apache
sudo service apache2 reload
####Making sure ZM and APIs work:
- open up a browser and go to
http://localhost/zm
- should bring up ZM - (OPTIONAL - just for peace of mind) open up a tab and go to
http://localhost/zm/api
- should bring up a screen showing CakePHP version with some green color boxes. Green is good. If you see red, or you don't see green, there may be a problem (should not happen). Ignore any warnings in yellow saying "DebugKit" not installed. You don't need it - open up a tab in the same browser and go to
http://localhost/zm/api/host/getVersion.json
If it responds with something like:
{
"version": "1.28.107",
"apiversion": "1.28.107.1"
}
Then your APIs are working
###Make sure you can view Monitor View
- Open up ZM, configure your monitors and verify you can view Monitor feeds
- If not, open up ZM console in your browser, go to
Options->Path
and make surePATH_ZMS
is set to/zm/cgi-bin/nph-zms
and restart ZM
###Make sure ZM and APIs work with security:
- Enable OPT_AUTH in ZM
- Log out of ZM in browser
- Open a NEW tab in the SAME BROWSER (important) and go to
http://localhost/zm/api/host/getVersion.json
- should give you "Unauthorized" along with a lot more of text - Go to another tab in the SAME BROWSER (important) and log into ZM
- Repeat step 3 and it should give you the ZM and API version
Congrats you now have ZM working with APIs and with security. The APIs tie into ZM security -- if you are not logged into ZM, the APIs won't work (hence the need to try it from the same browser instance)