francelife23
Cadet
- Joined
- Mar 5, 2018
- Messages
- 3
Introduction
Disclaimer:
I used myriad sources to piece this together, apologies to those not credited but the main sources were:
This will cover how to install and configure the ZM pre-requisites, there are different products/packages you can use, these are my preference:
Method
Step 1 – Create the jail
Step 2 – Install AMP
Execute the following steps on your new jail (not on the FreeNAS server)!!
Step 2A: Install Apache
Key things to do next:
Hope this helps someone.
Disclaimer:
- This is designed to provide a quick and dirty overview on getting ZoneMinder (ZM) up and running within a jail on FreeNAS. It is up to you to adapt this to your own circumstances and to ensure you secure everything after installation – this HOWTO does not result in a secure installation!!
- This guide assumes you are familiar with the basics of FreeNAS, fundamental Linux etc, you will need to be able to access the FreeNAS web UI and thereafter use the web shell or access the server via SSH. It does not cover how to use or configure ZM.
- I am not a Linux ninja and have compiled this guide based on my experience and information gleaned from the internet – feel free to contribute improvements however I will not be able to actively support people in their own adoption of this procedure.
- This guide was written in March 2018 using FreeNAS build 11.1 U2. Mileage may vary depending on your installed version.
I used myriad sources to piece this together, apologies to those not credited but the main sources were:
- “How To Install an Apache, MySQL, and PHP (FAMP) Stack on FreeBSD 10.1”by Mitchell Anicas [Available at: https://www.digitalocean.com/commun...ache-mysql-and-php-famp-stack-on-freebsd-10-1]
- “Installing ZoneMinder on Ubuntu 16.04 the easy way” by ZoneMinder [Available at: http://zoneminder.readthedocs.io/en/stable/installationguide/ubuntu.html#easy-way-ubuntu-16-04]
- Post on “ZM on FreeBSD” forum by Darius121 [Available at: https://forums.zoneminder.com/viewtopic.php?t=24460]
This will cover how to install and configure the ZM pre-requisites, there are different products/packages you can use, these are my preference:
- Web server – Apache (v2.4)
- Database server – MySQL (v5.6)
- PHP – Not optional!
Method
Step 1 – Create the jail
- Create a new jail from the default ‘blank’ template (for simplicity this guide assumes a brand-new jail, if you are using an existing FAMP jail etc you will have to adapt this and skip parts you have already done).
- Change the network settings and note the IP address of the jail for later use. Add storage as required for your jail and start/restart it as necessary.
- First ensure your package manager is up to date and configured (jails tend to get out of date, it might be easier to recreate your jail using a fresh downloaded template if you have issues here) along with a system update:
# pkg update -f
# pkg upgrade
- Now is also the time to install an alternative text editor if you don’t like VI:
# pkg install nano
Step 2 – Install AMP
Execute the following steps on your new jail (not on the FreeNAS server)!!
Step 2A: Install Apache
- Using the BSD package manager, install Apache with dependencies:
# pkg install apache24
- Configure Apache to autostart:
# sysrc apache24_enable=yes
- Then start Apache:
# service apache24 start
- Now go to a web browser, go to your jail’s IP address (NOT the FreeNAS’s!) and check you get the default It Works! Homepage served by Apache to confirm it installed ok, if not troubleshoot this before proceeding
- Install MySQL with dependencies:
# pkg install mysql56-server
- Configure MySQL to autostart:
# service mysql-server start
- Now check your MySQL instance is running by entering:
# mysql
- You should get a response that is not a Can't connect to local MySQL server… if not, troubleshoot this before proceeding.
- Install PHP with dependencies and MySQL options:
# pkg install mod_php56 php56-mysql php56-mysqli
- Copy the default PHP config:
# cp /usr/local/etc/php.ini-production /usr/local/etc/php.ini
- Now using your favourite editor (Nano here) open the Apache config file for writing:
# nano /usr/local/etc # nano apache24/httpd.conf
- Add the following to the end of the file:
Code:
<IfModule dir_module> DirectoryIndex index.php index.html <FilesMatch "\.php$"> SetHandler application/x-httpd-php </FilesMatch> <FilesMatch "\.phps$"> SetHandler application/x-httpd-php-source </FilesMatch> </IfModule>
- Now save and exit.
- Open the PHP configuration file for writing:
# nano /usr/local/etc/php.ini
- Uncomment the date.timezone line (if necessary) and append the appropriate details following the guidance at http://php.net/manual/en/timezones.php, the amended line should be (if you live in UK!):
date.timezone = Europe/London
- Now conduct a restart of Apache to check you didn’t mess anything up, if Apache doesn’t start, troubleshoot before proceeding:
# service apache24 restart
- If you want to be sure, you can also check PHP is installed correctly by setting up a PHP page calling the PHP info function and temporarily configuring Apache to host it – Google it for more info.
- If you have got this far, you are now ready to install ZM.
- Install ZM with dependencies:
# pkg install zoneminder
- Configure ZM to autostart:
# sysrc zoneminder_enable=yes
- Now we configure the core ZM elements, starting with initialising the ZM database:
# mysql -uroot -p < /usr/local/share/zoneminder/db/zm_create.sql
- Troubleshoot any errors before proceeding
mysql -uroot -p -e "grant
select,insert,update,delete,create,alter,index,lock tables on zm.* to 'zmuser'@localhost identified by 'zmpass';"
- Troubleshoot any errors before proceeding, now ensure some key permissions are set (EDIT: you may need to try 744 for zm.conf if you get permission denied errors later):
# chmod 740 /usr/local/etc/zm.conf
# chmod 740 /usr/local/my.cnf
- Restart MySQL to take changes into effect:
# service mysql-server restart
- Open the Apache config file for writing:
# nano /usr/local/etc/apache24/httpd.conf
- Append the following:
Code:
<VirtualHost *:80> ServerName zm.freenas.local ServerAdmin email@example.com DocumentRoot "/usr/local/www/zoneminder/" <Directory "/usr/local/www/zoneminder"> Options FollowSymLinks AllowOverride All Require all granted </Directory> ScriptAlias /cgi-bin "/usr/local/www/zoneminder/cgi-bin" <Directory "/usr/local/www/zoneminder/cgi-bin"> Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch AllowOverride All Require all granted </Directory> LogLevel debug </VirtualHost>
- Save and exit. Then restart Apache again, troubleshooting any issues:
# service apache24 restart
- In a browser, go to the ZM jail’s IP address, you should get to the ZM main page – hooray! If not, review the above steps and troubleshoot as necessary.
- Finally, restart the jail and re-check ZM in the browser as above to ensure everything restarts ok.
Key things to do next:
- Secure MySQL, run:
mysql_secure_installation
- Check and update permissions on all directories and folders are appropriate/secure
- Change settings/passwords etc as required
- Reconfigure PHP/Apache/MySQL to use production settings
Hope this helps someone.
Last edited: