Difference between revisions of "Ubuntu Server 16.04 64-bit with Zoneminder 1.30.4 the easy way"

From ZoneMinder Wiki
Jump to navigationJump to search
Line 484: Line 484:
Note: To avoid problems with feeds from multiple cameras "fcgiwrap" should be configured to start at least as many processes as there are cameras. It can be done by adjusting DAEMON_OPTS in "/etc/default/fcgiwrap".
Note: To avoid problems with feeds from multiple cameras "fcgiwrap" should be configured to start at least as many processes as there are cameras. It can be done by adjusting DAEMON_OPTS in "/etc/default/fcgiwrap".


  nano /etc/default/fcgiwrap
  nano /etc/init.d/fcgiwrap


Enter (change the 1 to the number of cameras)
Enter (change the 1 to the number of cameras)

Revision as of 11:05, 30 June 2018

Zoneminder 1.30.4 on Ubuntu 16.04/16.10/17.04 Server

Ubuntu 16.04/16.10/17.04 with LAMP

This procedure can be used to install Zoneminder on a basic Ubuntu install, a server install or a desktop install.

Ubuntu basic install can be done from the net install CD (https://www.ubuntu.com/download/alternative-downloads) This is creates a CD from the file mini.iso. When prompted (tasksel) install standard system utilities, OpenSSH Server, and LAMP Server. This is the minimum that is required to set up and run Zoneminder and does not load other apps that are not needed.

Ubuntu Server Install: When prompted by Tasksel install OpenSSH Server, and LAMP Server.

Ubuntu Desktop: You will have to install tasksel in a terminal (sudo apt-get install tasksel) then run tasksel to install OpenSSH Server, and LAMP Server.

If you get a blank screen after installing Ubuntu 16.04 minimal install or server, press Alt + F1 to open a console.

Log in then become root:

sudo su

Make sure you are up to date

apt update
apt upgrade
apt dist-upgrade

At this point you should have Ubuntu 16.04 installed with LAMP which includes the default MySQL 5.7. You have the option to use Mariadb Server 10.0 which will replace MySQL 5.7 (Click on Options link in Contents above) or continue with MySQL 5.7..

You may want to set the system swap file usage. See: https://wiki.zoneminder.com/Common_Issues_with_Zoneminder_Installation_on_Ubuntu#Ubuntu_Swap_File

You will need to make a settings change to MySQL as follows:

NOTE: The MySQL default configuration file (/etc/mysql/mysql.cnf)is read through several symbolic links beginning with /etc/mysql/my.cnf as follows:

/etc/mysql/my.cnf -> /etc/alternatives/my.cnf /etc/alternatives/my.cnf -> /etc/mysql/mysql.cnf

/etc/mysql/mysql.cnf is a basic file

To better manage the MySQL server I recommend you copy the sample config file and replace the default my.cnf symbolic link.

This removes the current symbolic link

rm /etc/mysql/my.cnf  

This moves the MYSQL Configuration file

cp /etc/mysql/mysql.conf.d/mysqld.cnf /etc/mysql/my.cnf

To change MySQL settings:

nano /etc/mysql/my.cnf

In the [mysqld] section add the following

sql_mode = NO_ENGINE_SUBSTITUTION

Note: if you are installing on an existing database server you can use the following as an alternate to 'sql_mode = NO_ENGINE_SUBSTITUTION' (Thanks to "bodom" for this alternate):

init_connect = 'SET @@sql_mode = CASE CURRENT_USER() WHEN \'zmuser@localhost\' THEN \'NO_ENGINE_SUBSTITUTION\' ELSE @@sql_mode END;'


Ctrl+o Enter to save

CTRL+x to exit

Restart MySQL

systemctl restart mysql

Recommended: Secure MySQL.

mysql_secure_installation


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.

apt 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.

Install Zoneminder 1.30.4

Add Repository

NOTE:You may need to run: "apt install software-properties-common" if you did the minimal net install of Ubuntu.

add-apt-repository ppa:iconnor/zoneminder

Update Sources

apt update

Install Zoneminder

apt install zoneminder

Create a new user

adduser www-data video

Enable CGI, Zoneminder and rewrite configuration in Apache.

a2enmod cgi
a2enconf zoneminder
a2enmod rewrite

Fix Permissions

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

Enable and start Zoneminder

systemctl enable zoneminder
service zoneminder start

Add timezone to PHP

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

Search for [Date] (Ctrl + w then type Date and press Enter) and make changes as follows for your time zone. Make sure to remove the ; from the front of date.timezone

[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


IMPORTANT FINAL STEP: Open Zoneminder in a web browser (http://server-ip/zm). Click on Options - Paths and change PATH_ZMS to /zm/cgi-bin/nph-zms




Optional Upgrade to MariaDB Server 10.0. before installing Zoneminder

MariaDB has some enhanced features which do not exist in MySQL and thus migration back to MySQL might not always work.

NOTE: This procedure is to upgrade to Mariadb before installing Zoneminder!

Upgrade the LAMP installed MySQL 5.7 to Mariadb with the command:

apt install mariadb-server

Secure Mariadb, create root password et. al.

mysql_secure_installation

NOTE:The MySQL/MariaDB configuration file is located at: /etc/mysql/mysql.conf.d/mysqld.cnf To better manage the MariaDB server I recommend you move the config file and replace the default my.cnf symbolic link (this also works for MySQL 5.6).

rm /etc/mysql/my.cnf  (this removes the current symbolic link)
cp /etc/mysql/mariadb.conf.d/50-server.cnf /etc/mysql/my.cnf

Change Mariadb settings:

nano /etc/mysql/my.cnf

Make the following changes:

character-set-server = latin1
collation-server = latin1_swedish_ci
innodb_file_per_table = 1


Note: The above character-collation settings are actually the Mariadb default. Changing back to default is necessary to avoid errors when logging into Zoneminder. This was added on 01APR17 but is not an April Fool! It may be necessary to align these settings with your regional language. The innodb_file_per_table setting insures you will get the best performance from the database but you will need to adjust settings as your system builds up events.

Ctrl+o Enter to save

CTRL+x to exit

A tool that you may want to install is mysqltuner. This is handy to see what database paramaters need to be adjusted as your ZM system builds up events.

apt install mysqltuner

Continue installing Zoneminder: [1]


Here is a link to manually install LAMP with Mariadb server Install MariaDB Server 10.0


Optional Upgrade to MariaDB Server 10.0. with Zoneminder (or other databases) installed

NOTE: This procedure is concerned with backing up and recreating the Zoneminder database. You can use the same commands, with other database names, if your system has other databases running in MySQL.

Stop Zoneminder

service zoneminder stop

Backup Zoneminder database (or other databases)

mysqldump -uroot -p zm > zm.sql

Upgrade the LAMP installed MySQL 5.7 to Mariadb with the command:

apt install mariadb-server

Secure Mariadb, create root password et. al.

mysql_secure_installation

NOTE: The MySQL/MariaDB configuration file is located at: /etc/mysql/mysql.conf.d/mysqld.cnf To better manage the MariaDB server I recommend you move the config file and replace the default my.cnf symbolic link.

Remove the current symbolic link

rm /etc/mysql/my.cnf  

Create new my.cnf

cp /etc/mysql/mariadb.conf.d/50-server.cnf /etc/mysql/my.cnf

Change Mariadb settings:

nano /etc/mysql/my.cnf

Make the following changes:

character-set-server = latin1
collation-server = latin1_swedish_ci
innodb_file_per_table = 1

Note: The above settings are actually the Mariadb default. Changing back to default is necessary to avoid errors when logging into Zoneminder. This was added on 01APR17 but is not an April Fool! It may be necessary to align these settings with your regional language.

Ctrl+o Enter to save

CTRL+x to exit

Create new empty zm database

mysql -uroot -p

You are now in the Mariadb console

CREATE DATABASE zm;

Quit Mariadb console

\q

Restore zm database from backup

mysql -uroot -p zm < zm.sql

Set permissions

mysql -uroot -p -e "grant all on zm.* to 'zmuser'@localhost identified by 'zmpass';"

Start Zoneminder

service zoneminder start

You should now be running Mariadb server!

Install Zoneminder on Ubuntu 16.04 with shell script

This will install Zoneminder by using a shell script with one basic command (how easy is that!)

You will need to copy the contents of the file from:Shell script zm_install

There are two scripts in this location. One is to be used on a Ubuntu system with LAMP installed. The second can be run on a bare Ubuntu system and it will install and configure the database for you (WARNING: This script installs Mariadb Server and Client and will replace MySQL if it is installed!!!)

Copy the script contents, open a terminal and run:

nano zm_install

and paste the contents of the script into the file. CTRL+o to save the file and CTRL+x to exit.

chmod 755 zm_install

Start the script by entering:

./zm_install

I have tested this on budgie-remix 16.04-1 desktop x64 and Ubuntu 16.04-1 server x64. This shell script should work on and Ubuntu 16.04 desktop (Mint, Lubuntu et. al.). You do not have to have LAMP, Apache or MySQL installed to run this. The script will install everything Zoneminder needs to function and set up Zoneminder! Good Luck!

While this script worked for me I can't be responsible if you loose data when you run this. It is intended for a new install not an upgrade.

Ubuntu 16.04 LEMP (NGNIX, Mariadb, PHP)

The setup of the LEMP server was developed from: https://www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mysql-php-lemp-stack-in-ubuntu-16-04

Start with a basic Ubuntu 16.04 install. You can use a server or desktop install. Do not install LAMP!

Become root

sudo su

Install Ngnix, Mariadb

apt install nginx 
apt install mariadb-server 

Secure the Mariadb server

mysql_secure_installation

NOTE:The MySQL/MariaDB configuration file is located at: /etc/mysql/mysql.conf.d/mysqld.cnf To better manage the MariaDB server I recommend you move the config file and replace the default my.cnf symbolic link

Removes the current symbolic link

rm /etc/mysql/my.cnf  

Create a new my.cnf

cp /etc/mysql/mariadb.conf.d/50-server.cnf /etc/mysql/my.cnf

Change Mariadb settings:

nano /etc/mysql/my.cnf

Make the following changes:

character-set-server = latin1
collation-server = latin1_swedish_ci

Note: The above settings are actually the Mariadb default. Changing back to default is necessary to avoid errors when logging into Zoneminder. This was added on 01APR17 but is not an April Fool! It may be necessary to align these settings with your regional language.

Ctrl+o Enter to save

CTRL+x to exit

Restart Mariadb

systemctl restart mysql

Install PHP components

apt install php-fpm php-mysql fcgiwrap

Edit the php.ini file

nano /etc/php/7.0/fpm/php.ini

Locate (Ctrl+w) cgi.fix_pathinfo=1 and change to

cgi.fix_pathinfo=0

Remember to remove the leading ;

Also fix date. Search for [Date] (Ctrl + w then type Date and press Enter) and make changes as follows for your time zone. Make sure to remove the ; from the front of date.timezone

[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 php-fpm

systemctl restart php7.0-fpm

Install Zoneminder

Add Repository

NOTE:You may need to run: "apt install software-properties-common" if you did the minimal net install of Ubuntu.

add-apt-repository ppa:iconnor/zoneminder

Update Sources

apt update

Install Zoneminder

apt install zoneminder

Create a new user

adduser www-data video

Fix Permissions

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

Enable and start Zoneminder

systemctl enable zoneminder
service zoneminder start


Edit the Ngnix default configuration.

nano /etc/nginx/sites-available/default

Locate the line "index index.html index.htm index.nginx-debian.html;" and add index.php

index index.php index.html index.htm index.nginx-debian.html;

Ctrl+o Enter to save

CTRL+x to exit

Create a Zoneminder conf file

nano /etc/nginx/zoneminder.conf

Enter the following into the zoneminder.conf file (This file was improved by databoy2k)

location /zm/cgi-bin {
    gzip off;
    alias /usr/lib/zoneminder/cgi-bin;

    include /etc/nginx/fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $request_filename;
    fastcgi_pass  unix:/var/run/fcgiwrap.socket;
}

location /zm {
#   if ($scheme ~ ^http:){
#       rewrite ^(.*)$  https://$host$1 permanent;
#   }

    gzip off;
    alias                   /usr/share/zoneminder/www;
    index                   index.php;

    location ~ \.php$ {
        if (!-f $request_filename) { return 404; }
        expires             epoch;
        include             /etc/nginx/fastcgi_params;
        fastcgi_param       SCRIPT_FILENAME         $request_filename;
        fastcgi_index       index.php;
        fastcgi_pass        unix:/var/run/php/php7.0-fpm.sock;
    }


    location ~ \.(jpg|jpeg|gif|png|ico)$ {
        access_log          off;
        expires         33d;
    }

    location /zm/api/ {
        alias                   /usr/share/zoneminder/www/api;
        rewrite ^/zm/api(.+)$ /zm/api/index.php?p=$1 last;
    }
}

Ctrl+o Enter to save

CTRL+x to exit

Edit the default sites enabled

nano /etc/nginx/sites-enabled/default

In the "server" section after listen [::] :80 default_Server; add

include /etc/nginx/zoneminder.conf;

Ctrl+o Enter to save

CTRL+x to exit

Restart Ngnix

service nginx restart

Note: If Nginx gives you an error on restart go back one step and re-enter include /etc/ngnix/zoneminder.conf;

IMPORTANT FINAL STEP: Open Zoneminder in a web browser (http://server-ip/zm). Click on Options - Paths and change PATH_ZMS to /zm/cgi-bin/nph-zms

Note: To avoid problems with feeds from multiple cameras "fcgiwrap" should be configured to start at least as many processes as there are cameras. It can be done by adjusting DAEMON_OPTS in "/etc/default/fcgiwrap".

nano /etc/init.d/fcgiwrap

Enter (change the 1 to the number of cameras)

DAEMON_OPTS="-f -c 1" 

Ctrl+o Enter to save

CTRL+x to exit