# PHP Weathermap v0.97c

#### Copyright © 2005-2013 Howard Jones, `howie@thingy.com`. (Website)

## Installation

### Command-Line Tool and Editor

#### Requirements

You will need the 'pcre' and 'gd' PHP modules in both your command-line and server-side (mod_php/ISAPI) PHP. The command-line tool runs using the command-line PHP, and the editor uses the server-side one. In some situations it is possible to have two completely different PHP installations serving these two - if you install from a package, then re-install from source, but to a different directory, for example. The editor and the CLI tool should both warn you if the part they need is not present.

>

The command-line tool uses the Console_Getopt PEAR module. This comes as standard with PEAR, so you should be able to just install PEAR to get it. This may be a seperate package/port/RPM on your system, or you may need to install it from pear.php.net

Before you start using it, you might want to change one PHP setting. Weathermap uses a fair bit of memory by PHP standards, as it builds the image for the map in memory before saving it. As a result, your PHP process may run out of memory. PHP has a 'safety valve' built-in, to stop runaway scripts from killing your server, which defaults to 8MB in most versions (this has changed in 5.2.x). This is controlled by the 'memory_limit =' line in php.ini. You may need to increase this to 32MB or even more if you have problems. These problems will typically show up as the process just dying with no warning or error message, as PHP kills the script.

#### Installation

Unpack the zip file into a directory somewhere. If you are intending to use the browser-based editor, then the directory that you unpack the zip file into should be within the 'web space' on the web server that runs your data-collection application (that is, Cacti, MRTG, or similar) - /var/www/html, /usr/local/www/data or whatever it is for you.

You can then use the pre-install checker to see if your PHP environment has everything it needs. To do this, you need to run a special `check.php` script, twice...

First, go to http://yourcactiserver/plugins/weathermap/check.php to see if your webserver PHP (mod_php, ISAPI etc) is OK. Then, from a command-prompt run `php check.php` to see if your command-line PHP is OK. If any modules or functions are missing, you will get a warning, and an explanation of what will be affected (not all of the things that are checked are deadly problems).

You'll need to edit two lines in the `weathermap` file:

- If you are on a Unix-based platform (BSD, OS X, Linux etc), the path in the very top line should be the full path to your command-line php executable (usr/bin/php, or /usr/local/bin/php usually).
- Around line 30 or so, you may need to change the path to your rrdtool executable, if you are intending to use RRD-based datasources for your maps.

#### Testing

That should be it! You should be able to run
`./weathermap`
or
`php weathermap` (on Windows you will need this one)

from a shell or command prompt, and get a (rather boring) `weathermap.png` file in return. If you don't, you should get some kind of error to help you figure out why.

#### Editor

Once you have weathermap itself working, continue onto the editor:

Copy the `editor-config.php-dist` file to `editor-config.php`. If you use Cacti, and want to be able to pick data sources from your Cacti installation by name, edit the file and make sure that the line that sets `$cacti_base` is correct, and that the base URI below that is also correct for your Cacti installation (these two lines are marked CHANGE in the file).

Make sure that your webserver can write to the configs directory. To do this, you need to know which user your webserver runs as (maybe 'nobody', 'www' or 'httpd' on most *nixes) and then run:

    chown www configs
                                    chmod u+w configs

In a pinch, you can just `chmod 777 configs`, but this really isn't a recommended solution for a production system.

On Windows, the same applies - the user that runs the webserver runs as should have permissions to write new files, and change existing files in the configs folder.

Since version 0.97, you now also need to enable the editor. The reason is so that you can't have the editor enabled without knowing about it. The editor allows access to your config files without authentication, so you should consider using features in your webserver to limit who can access `editor.php`. For example, on an Apache server, something like:

                                <Directory /var/www/html/weathermap>
                                    <Files editor.php>
                                        Order Deny,Allow
                                        Deny from all
                                        Allow from 127.0.0.1
                                    </FilesMatch>
                                </Directory>

When you are happy that the world can't edit your maps, then enable the editor. This is done by editing the top of editor.php and changing `$ENABLED=false;` to `$ENABLED=true;`

You should now be able to go to http://yourserver/wherever-you-unpacked-weathermap/editor.php in a browser, and get a welcome page that offers to load or create a config file. That's it. All done. Please see the editor manual page for more about using the editor!

Important Security Note: The editor allows anyone who can access editor.php to change the configuration files for your network weathermaps. There is no authentication built-in for editing, even with the Cacti Plugin. This is why the configuration file doesn't exist by default - the editor won't work until you choose to make it work. It's recommended that you either:

- change the ownership of configuration files so that the editor can't write to them once they are complete, or
- use your webserver's authentication and access control facilities to limit who can access the editor.php URL. On apache, this can be done using the FilesMatch directive and mod_access.