To Change MySQL Settings

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 11

To change MySQL settings:

nano /etc/mysql/my.cnf

In the [mysqld] section add the following

sql_mode = NO_ENGINE_SUBSTITUTION

CTRL+o then [Enter] to save

CTRL+x to exit

Restart MySQL

systemctl restart mysql

Step 4: Install ZoneMinder

apt-get install zoneminder

Step 5: Configure the ZoneMinder Database

mysql -uroot -p < /usr/share/zoneminder/db/zm_create.sql


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

Step 6: Set permissions

Set /etc/zm/zm.conf to root:www-data 740 and www-data access to content

chmod 740 /etc/zm/zm.conf


chown root:www-data /etc/zm/zm.conf
chown -R www-data:www-data /usr/share/zoneminder/

Step 7: Configure Apache correctly:

a2enconf zoneminder
a2enmod cgi
a2enmod rewrite

Step 8: Enable and start Zoneminder

systemctl enable zoneminder


systemctl start zoneminder

Step 9: Edit Timezone in PHP


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

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

CTRL+o then [Enter] to save

CTRL+x to exit

Step 10: Reload Apache service

systemctl reload apache2

Step 11: Making sure ZoneMinder works

1. Open up a browser and go to http://hostname_or_ip/zm - should bring up ZoneMinder


Console
2. (Optional API Check)Open up a tab in the same browser and go
to http://hostname_or_ip/zm/api/host/getVersion.json

If it is working correctly you should get version information similar to the example
below:
{
"version": "1.29.0",
"apiversion": "1.29.0.1"
}

Congratulations Your installation is complete

PPA install may need some tweaking of ZMS_PATH in ZoneMinder


options. Socket_sendto or no live streaming

Easy Way: Ubuntu 14.x


These instructions are for a brand new ubuntu 14.x system which does not have
ZM installed.
Step 1: Either run commands in this install using sudo or use the below to become root

sudo -i

Step 2: Install ZoneMinder

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

(just press OK for the prompts you get)

Step 3: Set up DB

mysql -uroot -p < /usr/share/zoneminder/db/zm_create.sql


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

Step 4: Set up Apache

a2enconf zoneminder
a2enmod rewrite
a2enmod cgi

Step 5: Make zm.conf readable by web user.

sudo chown www-data:www-data /etc/zm/zm.conf

Step 6: Edit Timezone in PHP

nano /etc/php5/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

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

CTRL+o then [Enter] to save

CTRL+x to exit

Step 7: Restart Apache service and start ZoneMinder


service apache2 reload
service zoneminder start

Step 8: Making sure ZoneMinder works

1. Open up a browser and go to http://hostname_or_ip/zm - should bring up ZoneMinder


Console
2. (Optional API Check)Open up a tab in the same browser and go
to http://hostname_or_ip/zm/api/host/getVersion.json

If it is working correctly you should get version information similar to the example
below:
{
"version": "1.29.0",
"apiversion": "1.29.0.1"
}

Congratulations Your installation is complete

Harder Way: Build Package From Source


(These instructions assume installation from source on a ubuntu 15.x+ system)

Step 1: Grab the package installer script

wget https://raw.githubusercontent.com/ZoneMinder/ZoneMinder/master/utils/do_debian_package.sh
chmod a+x do_debian_package.sh

Step 2: Update the system

sudo apt-get update

Step 3 Create the package

To build the latest master snapshot:

./do_debian_package.sh `lsb_release -a 2>/dev/null | grep Codename | awk '{print $2}'` `date


+%Y%m%d`01 local master

To build the latest stable release:

./do_debian_package.sh `lsb_release -a 2>/dev/null | grep Codename | awk '{print $2}'` `date


+%Y%m%d`01 local stable
Note that the lsb_release -a 2>/dev/null | grep Codename | awk '{print $2}' part simply
extracts your distribution name - like “vivid”, “trusty” etc. You can always replace it by
your distro name if you know it. As far as the script goes, it checks if your distro is
“trusty” in which case it pulls in pre-systemd release configurations and if its not “trusty”
it assumes its based on systemd and pulls in systemd related config files.

(At the end the script will ask if you want to retain the checked out version of
ZoneMinder. If you are a developer and are making local changes, make sure you
select “y” so that the next time you do the build process mentioned here, it keeps your
changes. Selecting any other value than “y” or “Y” will delete the checked out code and
only retain the package)

This should now create a bunch of .deb files

Step 4: Install the package

sudo gdebi zoneminder_<version>_<arch>.deb


(example sudo gdebi zoneminder_1.29.0-vivid-2016012001_amd64.deb)

This will report DB errors - ignore - you need to configure the DB and some other
stuff

Step 5: Post install configuration

Now that you have installed from your own package you can resume following the
standard install guide for your version, start at the step after Install Zoneminder.

Hints
Make sure ZoneMinder and APIs work with security

1. Enable OPT_AUTH in ZoneMinder


2. Log out of ZoneMinder in browser
3. 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
4. Go to another tab in the SAME BROWSER (important) and log into ZM
5. Repeat step 3 and it should give you the ZM and API version

Socket_sendto or no live streaming

After you have setup your camera make sure you can view Monitor streams, if not
check some of the common causes:

 Check Apache cgi module is enabled.


 Check Apache /etc/apache2/conf-enabled/zoneminder.conf 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.

Changed Default DB User

If you have changed your DB login/password from zmuser/zmpass, you need to update
these values in zm.conf and the API’s database.php file.

1. Edit zm.conf to change ZM_DB_USER and ZM_DB_PASS to the values you used.
2. Edit databse.php which can be found in the web server folder
zoneminder/www/api/app/Config

There is a class there called DATABASE_CONFIG - change the $default array to reflect
your new details. Example:

public $default = array(


'datasource' => 'Database/Mysql',
'persistent' => false,
'host' => 'localhost',
'login' => 'mynewDBusername',
'password' => 'mynewDBpassword'
'database' => 'zm',
'prefix' => '',
//'encoding' => 'utf8',
);

Next Previous
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-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.

Install Zoneminder

apt-get install zoneminder php-gd

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


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

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

Fix Permissions

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

Edit zoneminder.conf

nano /etc/apache2/conf-available/zoneminder.conf

Add a - before Indexes and a + before FollowSymLinks

<Directory /usr/share/zoneminder/www>
Options -Indexes +FollowSymLinks

Make sure the following is at the bottom of the file

<Directory /usr/share/zoneminder/www/api>
AllowOverride All
</Directory>

Ctrl+o Enter to save


CTRL+x to exit
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

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

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-get 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

To change Mariadb settings:

nano /etc/mysql/my.cnf

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-get install mysqltuner

Continue installing Zoneminder: https://wiki.zoneminder.com/Ubuntu_Server_16.04_64-


bit_with_Zoneminder_1.29.0_the_easy_way#Install_Zoneminder

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-get 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

To change Mariadb settings:

nano /etc/mysql/my.cnf

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!

You might also like