Difference between revisions of "Common Issues with Zoneminder Installation on Ubuntu"

From ZoneMinder Wiki
Jump to navigationJump to search
Line 539: Line 539:
  sudo su
  sudo su


Add Repository
Add Repository (This adds the PPA master which is for testing only!)


  add-apt-repository ppa:iconnor/zoneminder-master
  add-apt-repository ppa:iconnor/zoneminder-master
Line 553: Line 553:
Upgrade the installation
Upgrade the installation


  apt-get upgrade
  apt-get upgrade
 
Note: You may have to do apt-get dist-upgrade


Configure Apache
Configure Apache

Revision as of 10:46, 17 January 2016

05JAN15

With some changes “in-the-works” for Ubuntu installs by the hard working volunteers who keep Zoneminder up-to-date, it was recommended that we post fixes/instructions for some issues that continue to surface. One difference will be that the Zoneminder install will no longer automatically install the zm database in MySQL. This document will likely grow over time but may become obsolete as procedures become better documented.

Zoneminder "Master" PPA This is to remind you that software installed from the iconnor zoneminder-master PPA is BETA software and NOT recommended for production systems! BETA software may have some features that do not work correctly!


Zoneminder Database

See Database Tips and Tricks for more topics: http://www.zoneminder.com/wiki/index.php/General_Notes#Database_Tricks.2FTips

Enable and convert MySQL to innodb_file_per_table for Zoneminder

Note: You may wish to convert MyISAM tables to InnoDB tables before you proceed. Upgrading Zoneminder to 1.26 or newer should do this for you.

innodb_file_per_table is by default ON Mysql 5.6.6 and onwards. There is plenty of stuff on Google about pros & cons of innodb_file_per_table. This post details how to enable innodb_file_per_table on an existing database. Because innodb_file_per_table affects new tables only, created after innodb_file_per_table is enabled, we need to recreate old databases to force innodb_file_per_table on old tables and reclaim some disk space.

Become root

sudo su

Backup First Create a dir to take backups:

cd ~

Note: I found it helpful to create a file which contained the MySQL user and password. Otherwise you will have to enter the user and password for every operation.

nano .my.cnf

Enter this content

[client]
user=root
password=mysqlpass

Ctrl+o Enter to save

CTRL+x to exit


Make backup directory

mkdir backup
cd backup

Copy MySQL data files (raw) (If all goes well, we will not need this)

Stop Zoneminder

service zoneminder stop

If you have other services that use MySQL you will want to stop them and possibly Apache.

service mysql stop && cp -ra /var/lib/mysql mysqldata && service mysql start

Take mysqldump As soon as above line completes, take a mysqldump of all databases

mysqldump --routines --events --flush-privileges --all-databases > all-db.sql

Drop Databases Create a sql file to drop all databases EXCEPT mysql database

mysql -e "SELECT DISTINCT CONCAT ('DROP DATABASE ',TABLE_SCHEMA,' ;') FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA <> 'mysql' AND TABLE_SCHEMA <> 'information_schema';" | tail -n+2 > drop.sql

Verify if drop.sql has correct database names and then execute drop.sql queries.

mysql < drop.sql

Verify all InnoDB tables gone

SELECT table_name, table_schema, engine FROM information_schema.tables WHERE engine = 'InnoDB';

Remove InnoDB files Stop mysql server first

service mysql stop

Then

rm /var/lib/mysql/ibdata1 && rm /var/lib/mysql/ib_logfile0 && rm /var/lib/mysql/ib_logfile1

At this point most likely you will have only /var/lib/mysql/mysql directory only.

Enable innodb_file_per_table

Open my.cnf file

nano /etc/mysql/my.cnf

Add following line after [mysqld]

innodb_file_per_table

Ctrl+o Enter to save

CTRL+x to exit

Time to import from mysqldump Start mysql server now

service mysql start

Run mysql import

mysql < all-db.sql

Force mysql_upgrade (to generate performance_schema)

mysql_upgrade --force

That’s All!

Restart Zoneminder (and any other services you have stopped)

service zoneminder start

Check for proper operation and that all your events are present.

When you are satisfied that all is worling well remove the backup directory and password filr=e

cd ~
rm -r backup
rm .my.cnf

You are finished!

This procedure has been adopted from https://rtcamp.com/tutorials/mysql/enable-innodb-file-per-table. Thanks to Rahul Bansal!


Adding Permissions to allow Database Upgrade

Versions of Zoneminder up to and including 1.28.1 in Ubuntu would automatically add the zm database to MySQL. Beginning about August 2015 the development version from the iconnor-master PPA omitted this step becoming like the Debian install process. Manually adding the database to MySQL will be necessary.


To install the zm database (after doing apt-get install zoneminder)

Create Zoneminder database in MySQL (Note: this also creates the default Zoneminder user and permissions in MySQL)

This next step creates a file which contained the MySQL user and password. Otherwise you will have to enter the user and password on the command line which is not secure!

Go to the root directory

cd ~

Create a hidden password file

nano .my.cnf

Enter this content (but use your MySQL root password!)

[client]
user=root
password=(mysqlpass)

Ctrl+o Enter to save

CTRL+x to exit

Create database permissions

mysql -e "grant select,insert,update,delete,create,alter,lock tables on zm.* to 'zmuser'@localhost identified by 'zmpass';"


Remove password file

rm .my.cnf

Continue with the Zoneminder installation

Upgrades

Ubuntu 14.04 with MySQL 5.6 and Zoneminder from PPA

Note: 10NOV15 This procedure will not work as the version of Zoneminder in the PPA was removed. It will work for the version in the development PPA (zoneminder-master)

This procedure starts with Ubuntu Server 14.04-3 with LAMP added. Zoneminder is not installed. It is possible to upgrade a system running Zoneminder but it is not covered in this procedure.

Become root

sudo su

Stop MySQL

service mysql stop

Remove MySQL

apt-get purge mysql

Install MySQL 5.6 (will upgrade the MySQL client)

apt-get install mysql-server-5.6

Add Repository

add-apt-repository ppa:iconnor/zoneminder
apt-get update

Install Zoneminder

apt-get install zoneminder

Create Zoneminder database in MySQL (Note: this also creates the default Zoneminder user and permissions in MySQL)

This next step creates a file which contained the MySQL user and password. Otherwise you will have to enter the user and password on the

command line which is not secure!

Go to the root dir

cd ~

Create a hidden password file

nano .my.cnf

Enter this content

[client]
user=root
password=(mysqlpass)

Ctrl+o Enter to save

CTRL+x to exit

Create database

mysql < /usr/share/zoneminder/db/zm_create.sql 
mysql 
grant select,insert,update,delete on zm.* to 'zmuser'@localhost identified by 'zmpass';
\q (enter) (to quit)

Remove password file

rm .my.cnf

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

Add delay to allow MySQL to start before Zoneminder

nano /etc/init.d/zoneminder

Add sleep 15 as shown:

start() {
     sleep 15
     echo -n "Starting $prog: "

Ctrl+o Enter to save

CTRL+x to exit

Create a symbolic link

ln -s /etc/zm/apache.conf /etc/apache2/conf-enabled/zoneminder.conf

Create a new user

adduser www-data video

Enable CGI and Zoneminder configuration in Apache.

a2enmod cgi
a2enconf zoneminder
a2enmod rewrite

Start Zoneminder

service zoneminder start

Restart Apache

service apache2 reload

Note: You may need to edit my.cnf and change the value: sql_mode= to sql_mode=NO_ENGINE_SUBSTITUTION

Ubuntu 14.04 - ZM 1.26.5 or later to 1.28.109 or the latest PPA version

Note: 10NOV15 This procedure will not work as the version of Zoneminder in the PPA was removed. It will work for the version in the development PPA (zoneminder-master)

Note: 05DEC15 this procedure has been verified to work with the zoneminder-master PPA for Ubuntu 14.04 dated 04DEC15.

There are a couple of changes you will need to make to get ZM running with version 1.28.109

Become root

sudo su

Add Repository (not needed if you are running ZM 1.28.1) Note: if you need to remove a repository use: add-apt-repository --remove ppa:iconnor/zoneminder

add-apt-repository ppa:iconnor/zoneminder
apt-get update

Stop Zoneminder

service zoneminder stop

Upgrade the installation

apt-get upgrade  (may return nothing to upgrade)
apt-get dist-upgrade

You will be asked if you want to replace /etc/init.d/zoneminder. Choose "Y"

The database will not automatically update.

Go to the root directory

cd ~

Create a hidden password file

nano .my.cnf

Enter this content (but use your MySQL root password!)

[client]
user=root
password=(mysqlpass)

Ctrl+o Enter to save

CTRL+x to exit

Change permissions in your "ZM database to allow the creation of a table

mysql -e "grant select,insert,update,delete,create,alter,lock tables,index on zm.* to 'zmuser'@localhost identified by 'zmpass';"

Run the database upgrade

/usr/bin/zmupdate.pl  

Remove password file

rm .my.cnf

Add back the delay to allow MySQL to start before Zoneminder

nano /etc/init.d/zoneminder

Add sleep 15 as shown:

start() {
     sleep 15
     echo -n "Starting $prog: "

Ctrl+o Enter to save

CTRL+x to exit

Remove symbolic link

rm /etc/apache2/conf-enabled/zoneminder.conf

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

Enable Zoneminder and rewrite

a2enconf zoneminder
a2enmod rewrite

Start Zoneminder

service zoneminder start

Add timezone to PHP

nano /etc/php5/apache2/php.ini

Search for [Date] and make changes as follows for your time zone

[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
date.timezone = America/New_York

Ctrl+o Enter to save

CTRL+x to exit

Restart Apache

service apache2 restart

Open Zoneminder. Click on Options - Paths

Change PATH_ZMS to /zm/cgi-bin/nph-zms

Ubuntu 15.04 - ZM 1.26.5 or later to 1.28.109 or the latest PPA version

Note: 10NOV15 This procedure will not work as the version of Zoneminder in the PPA was removed. It will work for the version in the development PPA (zoneminder-master)

Note: This procedure verified for teh zoneminder-master PPA version dated 04DEC15

Become root

sudo su

Add Repository (not needed if you run 1.27.x or later)

add-apt-repository ppa:iconnor/zoneminder
apt-get update

Stop Zoneminder

systemctl stop zoneminder.service

Upgrade the installation

apt-get upgrade  (may return nothing to upgrade)
apt-get dist-upgrade

Note: the 04DEC15 1.28.109-vivid from the PPA master does a database upgrade automatically. The following database upgrade is not needed but I left it in place just-in-case...

This next step creates a file which contained the MySQL user and password. Otherwise you will have to enter the user and password on the command line which is not secure!

Go to the root dir

cd ~

Create a hidden password file

nano .my.cnf

Enter this content

[client]
user=root
password=(mysqlpass)

Ctrl+o Enter to save

CTRL+x to exit

Change permissions in your "ZM database to allow the creation of a table

mysql -e "grant select,insert,update,delete,create,alter,lock tables,index on zm.* to 'zmuser'@localhost identified by 'zmpass';"


Run the database upgrade

/usr/bin/zmupdate.pl  

Remove password file

rm .my.cnf

Configure Apache

rm /etc/apache2/conf-enabled/zoneminder.conf 
a2enmod rewrite
a2enmod cgi
a2enconf zoneminder


Start Zoneminder

service zoneminder start

Fix Permissions

chown -R www-data:www-data /usr/share/zoneminder/

Add timezone to PHP

nano /etc/php5/apache2/php.ini

Search for [Date] and make changes as follows for your time zone

[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
date.timezone = America/New_York

Ctrl+o Enter to save

CTRL+x to exit

Restart Services

service apache2 reload
systemctl start zoneminder.service


Open Zoneminder. Click on Options - Paths Italic text Change PATH_ZMS to /zm/cgi-bin/nph-zms

If Zoneminder does not start when you boot your server, run these commands:

systemctl stop zoneminder.service
systemctl disable zoneminder.service
systemctl enable zoneminder.service
systemctl start zoneminder.service

Reboot your server and check that Zoneminder started.

Ubuntu 15.10 - ZM 1.28.1 to 1.29.0 the the latest PPA version

Become root

sudo su

Add Repository (This adds the PPA master which is for testing only!)

add-apt-repository ppa:iconnor/zoneminder-master

Update package list

apt-get update

Stop Zoneminder

systemctl stop zoneminder.service

Upgrade the installation

apt-get upgrade 

Note: You may have to do apt-get dist-upgrade

Configure Apache

rm /etc/apache2/conf-enabled/zoneminder.conf
a2enmod rewrite

a2enconf zoneminder

Fix Permissions

chown -R www-data:www-data /usr/share/zoneminder/

Add timezone to PHP

nano /etc/php5/apache2/php.ini

Search for [Date] and make changes as follows for your time zone

[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
date.timezone = America/New_York

Ctrl+o Enter to save

CTRL+x to exit

Restart Services

systemctl start zoneminder
service apache2 reload

Open Zoneminder in a browser. Click on Options - Paths

Check that PATH_ZMS is set to: /zm/cgi-bin/nph-zms

Zoneminder 1.29.0 from PPA Master on Ubuntu 14.04

Note: this is for testing purposes only!

Install Basic Server (if you used the mini.iso), OpenSSH Server, and LAMP Server

Log in then become root:

sudo su

Make sure you are up to date

apt-get update
apt-get upgrade
apt-get dist-upgrade


Add Repository

add-apt-repository ppa:iconnor/zoneminder-master

Update Sources

apt-get update

Install Zoneminder

apt-get install zoneminder

You may be prompted to set up Nulmailer. You may accept the defaults and set this up later if you want to use it.

Create Zoneminder database in MySQL (Note: this also creates the default Zoneminder user and permissions in MySQL)

This next step creates a file which contained the MySQL user and password. Otherwise you will have to enter the user and password on the command line which is not secure!

Go to the root dir

cd ~

Create a hidden password file

nano .my.cnf

Enter this content

[client]
user=root
password=(mysqlpass)

Ctrl+o Enter to save

CTRL+x to exit

Create database

mysql < /usr/share/zoneminder/db/zm_create.sql 
mysql -e "grant select,insert,update,delete,create,alter,lock tables,index on zm.* to 'zmuser'@localhost identified by 'zmpass';"

Remove password file

rm .my.cnf

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

Add delay to allow MySQL to start before Zoneminder

nano /etc/init.d/zoneminder

Add sleep 15 as shown:

start() {
     sleep 15
     echo -n "Starting $prog: "

Ctrl+o Enter to save

CTRL+x to exit


Create a new user

adduser www-data video

Enable CGI, Zoneminder and rewrite configuration in Apache.

a2enmod cgi
a2enconf zoneminder
a2enmod rewrite

Start Zoneminder

service zoneminder start

Add timezone to PHP

nano /etc/php5/apache2/php.ini

Search for [Date] (Ctrl + w then type Date and press Enter) and make changes as follows for your time zone

[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
date.timezone = America/New_York

Ctrl+o Enter to save

CTRL+x to exit

Restart Apache

service apache2 reload

Open Zoneminder in a web browser (http://server-ip/zm).

Click on Options - Paths Change PATH_ZMS to /zm/cgi-bin/nph-zms

Zoneminder 1.29 from PPA Master on Ubuntu 15.04 or 15.10

Note: this is for testing purposes only!

Install Basic Server (if you used the mini.iso), OpenSSH Server, and LAMP Server

Log in then become root:

sudo su

Make sure you are up to date

apt-get update
apt-get upgrade
apt-get dist-upgrade


Add Repository

add-apt-repository ppa:iconnor/zoneminder-master

Update Sources

apt-get update

Install Zoneminder

apt-get install zoneminder

You may be prompted to set up Nulmailer. You may accept the defaults and set this up later if you want to use it.

As of 05JAN16 you will see a message "Errors were encountered while processing: zoneminder" This is because the installer was expecting the database to be set up. Ignore this and continue setting up the database.

Create Zoneminder database in MySQL (Note: this also creates the default Zoneminder user and permissions in MySQL)

This next step creates a file which contained the MySQL user and password. Otherwise you will have to enter the user and password on the command line which is not secure!

Go to the root dir

cd ~

Create a hidden password file

nano .my.cnf

Enter this content

[client]
user=root
password=(mysqlpass)

Ctrl+o Enter to save

CTRL+x to exit

Create database

mysql < /usr/share/zoneminder/db/zm_create.sql 
mysql -e "grant select,insert,update,delete,create,alter,lock tables,index on zm.* to 'zmuser'@localhost identified by 'zmpass';"

Remove password file

rm .my.cnf

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

Create a new user

adduser www-data video

Enable CGI, Zoneminder and rewrite configuration in Apache.

a2enmod cgi
a2enconf zoneminder
a2enmod rewrite

Start Zoneminder

service zoneminder start

Add timezone to PHP

nano /etc/php5/apache2/php.ini

Search for [Date] (Ctrl + w then type Date and press Enter) and make changes as follows for your time zone

[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
date.timezone = America/New_York

Ctrl+o Enter to save

CTRL+x to exit

Restart Apache

service apache2 reload

Open Zoneminder in a web browser (http://server-ip/zm).

Click on Options - Paths Change PATH_ZMS to /zm/cgi-bin/nph-zms