== Origin ==

This port project started its life based on quadra's original port for
version 1.19.2.  Brooktree (bktr) video input support code written by
quadra is virtually unchanged in this port other than some function
argument changes to match the latest ZoneMinder version (1.22.3).
Although this code compiles, I have not tested its functionality.
Currently, I only have two Axis 206 network cameras, which work fine,
but I have not tested the set up with any other camera
configurations.

I have tested this port on FreeBSD 5.5 (i386) as well as FreeBSD 6.2
(i386) without any problems.

== Preparation ==

* Download the port (zoneminder-freebsd-port-1.22.3p[version].tgz)
* Become root and 'cd' to /usr/ports/multimedia/
* Extract the port files.  You know how to do 'tar zxf' right?

You should now have /usr/ports/multimedia/zoneminder/

Now, go to the directory and look at files/patch-SharedMem.pm

What this patch does is to hard-wire native size to 4 (32-bits).
On FreeBSD, Perl is configured with -Duse64bitint by default and the
method that is used by SharedMem.pm to determine architectural bit
width incorrectly considers an i386 machine as 64-bit capable.  I'm 
not a perl expert -- in fact, I hate perl -- and I really have no
idea how to properly determine pointer size in Perl, so this patch
exists.  Obviously, if you are running FreeBSD-AMD64 (or Alpha or
something, although I have no idea if this software would work on
that architecture), you will want to get rid of this patch file.
Just delete it _before_ you make.

And if you're bored, feel free to go through all the patch files just
marvelling at all the trouble I had to go through ^_^;

Now that we've gotten that little quirk out of the way, we'll move on
to Makefile.  Open Makefile using your favorite text editor and modify
the following items if they're not suitable for you.

* WWWDIR : This is where your web server will serve from.  If you
  already have apache installed, you should point this to the same
  place where apache thinks is the web base.  Default is
  /usr/local/www, as can be seen in the Makefile.
* ZM_DB_HOST : This is where mysql server runs.  If you're running
  mysql server on a different machine, you'll want to update this
  line, but I'm not sure if you can avoid installing mysql on this
  machine.  Disk space is cheap, so I don't think it's that big a deal
  having mysql just sitting there, as long as it's not started.
* ZM_DB_NAME : This is the database name that ZoneMinder will use.
  I'm pretty sure ZoneMinder won't mind sharing a base database with
  other applications, but it certainly doesn't hurt to let it have its
  own database space, so this defaults to "zm"
* ZM_DB_USER and ZM_DB_PASS are username and password for the
  database.

We're almost ready to "make," but first, consider the following points
and just imagine how things can break based on your situation.

* If you do not have apache installed, this port will install version
  1.xx.xx of apache.  On the other hand, if you already have apache
  2.xx.xx installed, I do not know what will happen.  My guess is that
  things will work just fine since php5 port will see apache2
  installation and skip apache1 installation.
* If you have mysql version other than 5.0.xx installed, this port
  build will probably fail.  Even if it doesn't fail, you probably do
  not want multiple versions of mysql installed on your machine.  You
  can either edit the dependency in the Makefile to point to your
  version of mysql, or get rid of the dependency statement for mysql.
  Getting rid of it is not as nice, but I'm sure you're able to keep
  the dependencies in mind when messing around with ports in the
  future.
* If you have PHP4 installed, you should modify the dependencies in
  the Makefile to point to php4-extensions instead of
  php5-extensions.  I know for a fact that both versions work fine
  with ZoneMinder.
* I have not set up dependencies for perl modules Device::SerialPort
  and X10::ActiveHome because I do not have PTZ camera and my X10 is
  handled by another dedicated machine.  If you want this, you'll want
  to tinker with the port some more.  You can also manually install
  those ports (if they exist) before doing make.  I imagine
  ZoneMinder's configure script will pick them up.

That's about it.  Let's make!

== Making ==

There's really nothing special about making.  Just 'make' will do.
However, during the dependency builds, make sure PHP install includes
the apache module.  If you already have PHP installed without apache
module, you can always tinker with the Makefile in
/usr/ports/lang/php5/ and do 'make deinstall' followed by 'make
reinstall' to reinstall the port with additional modules.

If the build fails, take a deep breath, yell at your computer for
a moment, and try to figure out if you messed up anything while
changing the Makefile in one of the above steps.  If you do not
believe you've done anything wrong and still can't figure out why
the build fails, there's always the forum....

If it builds fine, feel free to 'make install'

However, do NOT 'make clean' yet!

== Seeding the database ==

If this is the first time installing ZoneMinder, you'll need to seed
the mysql database with ZoneMinder's configuration information.  To do
this, follow these steps as a root user.

First, if this is the first time mysql was installed, you'll want to
consider where you want the database files to reside.  Default is
/var/db/mysql/ but you may have set up a dedicated partition for it.
If you want to change it, just put the following line in /etc/rc.conf

* mysql_dbdir="/somewhere/else/you/want"

Obviously, you'll want this line in there, too:

* mysql_enable="YES"

Now, start the sucker up.

shell> /usr/local/etc/rc.d/mysql-server start

Assuming it started fine, give it a few seconds and then continue.
Note that you should be at /usr/ports/multimedia/zoneminder/ for the
following steps.

shell> mysql -h localhost -u root -p

This will ask for a password.  Just press enter to go with an empty
password.  You should now be in mysql command line interface.

mysql> source work/ZoneMinder-1.22.3/db/zm_create.sql

Above runs bunch of SQL commands from the file, seeding the
database.

mysql> grant select,insert,update,delete on zm.* to 'zmuser'@localhost identified by 'zmpass'; flush privileges;

Above sets up permissions.  Note that if you changed database name,
user name, or password in the Makefile, you'll need to modify above
command accordingly.

mysql> quit

That one should be obvious to you.

== Post-Installation Quirks ==

PHP5 installation does not necessarily set up the apache configuration
file properly.  You will want to make sure that following lines are in
apache configuration file, /usr/local/etc/apache/httpd.conf

* AddType application/x-httpd-php .php
* AddType application/x-httpd-php-source .phps

While you're at it, you might also want to check that following line
is in the configuration file.

* LoadModule php5_module libexec/apache/libphp5.so

== Automatic Execution at Boot ==

Obviously, if this is to be used as a security device, you'll want it
to start automatically on a reboot.  Again obviously, you need to have
both apache and mysql start up as well, unless of course, you're
running mysql on a remote machine.  If you are, I'm sure you're an
expert at this stuff already.

Add following lines into /etc/rc.conf, if not already present.  Order
is not important.

* apache_enable="YES"
* mysql_enable="YES"
* zm_enable="YES"

Just for your information, I had to put 'sleep 10' in ZoneMinder
startup script because mysql port does not become available
immediately after mysql startup script finishes.

== More Quirks ==

Depending on the number of cameras and their resolution settings, you
may need a lot more shared memory than provided by a default kernel.
If you've never built a custom kernel before, umm, time for you to
read the FreeBSD Handbook.  It can be found at
/usr/share/doc/handbook/index.html or at http://freebsd.org/

For the rest of you, just add a reasonable-looking version of the
following lines into your kernel configuration file and go though the
buildkernel, installkernel process.

* options SHMMAXPGS=65536
* options SHMMNI=384
* options SHMSEG=256

I think above gives maximum of 256MB of shared memory.  SHMMNI
statement probably isn't required since ZoneMinder probably creates
one big instance per camera instead of many little instances.  I'm not
sure about the last one.  Whatever the case, above works for me with
two Axis 206 cameras.

Adding the following line into /etc/sysctl.conf may speed up the
shared memory accesses, so even though it's not required, it's
probably a good idea.

* kern.ipc.shm_use_phys=1

== Modify php.ini ===
Change in php.ini short_open_tag to On (short_open_tag = On)

That's all folks!
