ZoneMinder: Bareword "ZM_PATH_LOGS" not allowed while "strict subs" in use

Since a recent burglary I have been using ZoneMinder to provide CCTV security for my house on my Ubuntu 12.04 machine. I noticed earlier today that zoneminder had stopped running over the weekend and when I tried to start the service again, I got the following error:

Starting ZoneMinder: Bareword "ZM_PATH_LOGS" not allowed while "strict subs" in use at /usr/share/perl5/ZoneMinder/ line 153.
BEGIN not safe after errors--compilation aborted at /usr/share/perl5/ZoneMinder/ line 168.
Compilation failed in require at /usr/share/perl5/ line 34.
BEGIN failed--compilation aborted at /usr/share/perl5/ line 34.
Compilation failed in require at /usr/bin/ line 37.
BEGIN failed--compilation aborted at /usr/bin/ line 37.

Looking through the ZoneMinder code I discovered that the error indicated that a configuration variable somehow wasn't set. My first thought was that perhaps a new configuration variable had been added in an upgrade but hadn't been automatically added to the configuration file. So I added a line containing ZM_PATH_LOGS to /etc/zm/zm.conf but now when I tried to start zoneminder, I received a similar (but different error):

Starting ZoneMinder: Bareword "ZM_USE_DEEP_STORAGE" not allowed while "strict subs" in use at /usr/share/perl5/ZoneMinder/ line 207.
BEGIN not safe after errors--compilation aborted at /usr/share/perl5/ZoneMinder/ line 226.
Compilation failed in require at /usr/share/perl5/ line 35.
BEGIN failed--compilation aborted at /usr/share/perl5/ line 35.
Compilation failed in require at /usr/bin/ line 37.
BEGIN failed--compilation aborted at /usr/bin/ line 37.

I added a line for this then another similar (but different) error appeared! Clearly this approach isn't correct. So I logged into mysql and had a poke around:

mysql -u XXX -p
mysql> show databases;
mysql> use zm;
mysql> show tables;
| Tables_in_zm   |
| Config         |
| ControlPresets |
| Controls       |
| Devices        |
| Events         |
| Filters        |
| Frames         |
| Groups         |
| Logs           |
| MonitorPresets |
| Monitors       |
| States         |
| Stats          |
| TriggersX10    |
| Users          |
| ZonePresets    |
| Zones          |
17 rows in set (0.00 sec)

mysql> select * from Config;

0 rows in set (0.00 sec)

Like in iPhone adverts, the above sequence is shortened. But the surprising result appears at the end: there are no lines in the Config table! This must be the culprit preventing ZoneMinder from starting.

Its not clear how this config table has been reset, as I don't recall updating the ZoneMinder packages recently, so I don't think its a botched database upgrade. I have restarted the machine that it runs on a couple of times over the weekend so perhaps the database got corrupted at shutdown, though I can't find any mysql logs complaining about this. In conclusion, I don't know how it happened! But if it happens again all the info is here.

To resolve this, I download the ubuntu package for zoneminder and had a look in the postinst install script to see how it initialised the database. It turns out there is an sql file at /usr/share/zoneminder/db/zm_create.sql which is applied at package installation. I edited this file and removed all lines that didn't affect the Config table and applied it manually.

Finally zoneminder started up (albeit without my configurations)! After reconfiguring zoneminder, I noticed in ZoneMinder's log database the following entry:

Config mismatch, expected 218 items, read 0. Try running ' -f' to reload config.

If this happens again, perhaps ' -f' is sufficient to fix it, instead of error-prone sql hacking. (update: according to commenters this does not work!)

And the moral of the story is: always backup your databases!

This entry was posted in Linux. Bookmark the permalink.

28 Responses to ZoneMinder: Bareword "ZM_PATH_LOGS" not allowed while "strict subs" in use

  1. Petter says:

    Thank you. This helped fixed my zoneminder setup. And the " -f" fails too 🙂 (same error "Bareword "ZM_PATH_LOGS" not allowed while "strict subs") ...

  2. Matt says:

    Thanks for this info - my ZM crashed over the weekend with the exact same cause - a completely truncated Config table. Someone over at ZM should probably look into this. And I'll be running mysqldump nightly. -f did not run, as it produced the same error. I had to extract the INSERT statements from zm_create.sql and run them.

    Thanks again.

  3. Mozzie says:

    I had a similar issue, and it took me a while to realize what was causing it. It seems that the original zm_create.sql doesn't have a "DROP IF EXISTS" line before table 'Logs'. Adding it allowed me to dump zm_create.sql to the database and everything seems to be working now.

  4. john says:

    Thanks for this info. I found the same error in my logs after trying to get ZM up & running for the 1st time and you saved me a lot of time & frustration trying to figure it out.

  5. Wayne says:

    Can anyone provide a little more detail on how to fix this? I have the same problem and am not a SQL expert. Do I only have to run the lines in the "Logs" section?


    • frankster says:

      Make a copy of that sql file and delete everything except the following sections:

      1. The line near the top that says "USE 'zm';"
      2. The section just below that has a "DROP TABLE" and "CREATE TABLE" applied to the "Config" table. This is 17 lines in my version of the sql file.
      3. The section that is about 620 lines into the file and starts with "delete from Config;" and has many lines beginning with "insert into Config...". This goes to the end of the file and is nearly 300 lines for me.

      You now have an sql file that modifies the zoneminder (zm) database by deleting the config table and recreating it, then it initialises the configuration options to default values. This means you will lose all your settings if you apply this sql file to the database. However as you are seeing this error you have probably already lost all your settings.

      To apply the script to the database you can use a command something like the following:

      cat modifiedscript.sql | mysql -u root -p

      Before you do this, I would recommend that you first verify that your Config table is empty:

      mysql -u root -p
      use zm;
      select * from Config;

      You should see "0 rows in set" if the Config table is empty (before you apply the sql script), or something like "218 rows in set" if it is full (after you apply the sql script).

  6. Wayne says:

    Thanks very much. It fixed my problem and zoneminder is now working again! I will implement a daily cron job to backup the database in case this happens again.

    • srinivas says:

      Hi Mr.Wayne i am srinivas please help me regarding above issue. When i am start zonemineder i am getting above error. For recovering that error the tutorial says that edit "/usr/share/zoneminder/db/zm_create.sql" this file. I am getting confusion how to edit that file. please help me regarding this(which lines i have to delete).please help me??????

  7. Winston says:

    Thank you for this. Like others, this happened on a server shutdown. I was fortunate enough that I had Config.MYD and .MYI backed off to tape recently, so restoring them allowed me to bring up Zoneminder again.

  8. Thank you so much, it worked for me, i just imported the "insert into config ..." from the sql file.

  9. MorFer says:


    To fix this problem, just access your database, delete every table in it and run the zm_create.sql again.

    It solved my problem here.

  10. robert says:

    imalinuxnoob but this is how it happened

    #TEENPARTY START -U alloffacebook -freeBOOZE
    #TEENPARTY STOP -U alloffacebook -freeBOOZE

  11. Felipe Caetano says:

    Thanks a lot frankster! That solved my problems here! =)

  12. Dan says:

    Thank you! It took me just 15 minute to fix this issue 🙂

  13. raptor says:

    thank you a lot, it works

  14. Steven says:

    This worked for me! Might be good to add that how-to in the actual article. Thanks smart people!

  15. Román P.C. says:

    Thank you very much, it worked for me too and without any problem!

  16. PKM says:

    Thank you very much ...........! Help me a log and saved my tons of time...!!

  17. sri says:

    I am also getting same error, for remove that error you told that edit this file /usr/share/zoneminder/db/zm_create.sql. I am not understand how to edit that file which does not effect config file. please help me.

  18. JonC says:

    Many many thanks Frankster, particularly for taking the trouble to provide the detailed instructions.... You've saved me burning the midnight oil....


  19. RayZ says:

    I had this problem when I upgraded Ubuntu from 13.04 to 13.10. I followed the instructions here to rebuild the Config table (THANKS for that), and after a reboot
    $ sudo service apache2 status
    $ sudo service mysql status
    $ sudo service zoneminder status
    shows that all of these are running. But when I try to access zoneminder locally or remotely by browsing to http:///zm, I get a 404 error.
    syslog indicates zoneminder is running and capturing motion detected images, which surprised me because I thought I would have to reconfigure everything. But I can't seem to access zm to see the images or configuration.
    Any clues?

    • frankster says:

      I haven't seen this exact problem myself, but I expect the problem lies within the configuration files in your /etc/apache2 directory.

      • RayZ says:

        I've been pulling out hair all day. Both /etc/zm/apache.conf and /etc/apache2/conf.d/zoneminder.conf look like:
        Alias /zm /usr/share/zoneminder
        ScriptAlias /cgi-bin /usr/share/zoneminder/cgi-bin

        php_flag register_globals off
        Options Indexes FollowSymLinks

        DirectoryIndex index.php

        /usr/share/zoneminder/index.php looks appropriate.
        Yet browsing to localhost/zm/ or localhost/zm/index.php returns "URL /zm/ was not found on this server".

        I'm shooting blanks at this point, as I don't understand what directs apache to the zoneminder page.

        • RayZ says:

          some of the text zoneminder.conf got stripped out:
          "Directory /usr/share/zoneminder" (in brackets) was before php_flag.
          "IfModule mod_dir.c" was before DirectoryIndex,
          "/IfModule" followed DirectoryIndex.
          "/Directory" followed "/IfModule"

  20. Leandro Torres says:

    From Argentina, I say thank you, thank you very much. I'm installing zoneminder on a raspberry pi 2 and if you don't post the solution I would throw it for my window. Thanks again.

  21. AlKi says:

    Had the same problem as well, -f did not help at first, it since it first loads data from the database, and then wants to have at least some kind of basic config values (same error "Bareword "ZM_PATH_LOGS" not allowed")
    My Solution looked a bit like yours but I found several problems/possible bugs in the /usr/share/zoneminder/db/zm_create.sql file:
    1) for EVERY table exept the Config table, there is a "DROP TABLE IF EXISTS '[Tablename]';" command - so I had to add this one to be sure - maybe this is to make sure no configuration data gets overwritten... but in this case there is no data in there anyway
    2) when this part of the sql file worked, the part after "-- Add in some sample control protocol definitions" did throw errors regarding duplicate keys. Remove it (of make these lines comments by "-- " !never forget the whitespace!)
    3) when I manually tried "DROP TABLE IF EXISTS 'Config';" I got a syntax error. "DROP TABLE IF EXISTS Config;" worked (I'm not that firm with sql, but why should it work in the sql-file?

    Anyway, after applying the modified file containing only lines for the Config-Table, -f did work, the client did start

  22. zmuser says:

    in my case, in installation manual for ubuntu 14.04 it is asked to import database dump with mysql -uroot -p < /usr/share/zoneminder/db/zm_create.sql
    this failed and halted due to error with creation of 'Logs' table
    edited the sql file to add DROP TABLE IF EXISTS `Logs`;
    before CREATE TABLE `Logs` (
    then imported the dump successfully
    and then zm service started correctly without errors

Leave a Reply

Your email address will not be published. Required fields are marked *