Cacti: Ubuntu 8.04 Cacti Plugin - Invalid PHP_SELF Path problem
Lately, I’ve been spending a lot of time with Cacti on my Ubunto 8 install. Cacti as we all know is a (great) PHP wrapper application around the rrdtool command. Cacti and rrdtool are typically used by network/systems administrators for graphing network conditions, churning out great looking graphs for various SNMP data.
I’ve been investigating whether I could use Cacti to graph other kinds of data like my website loading time etc. And, it does, brilliantly, but that’s another story for another day.
In any case, after getting Cacti running smoothly on Ubuntu, I decided to try the Cacti Plugin Architecture to see if I could learn how to build some plugins for Cacti. And it wasn’t so straightforward.
It seems the Cacti Plugin Architecture patch is not friendly towards a default Ubuntu install. That’s because Ubuntu places the Cacti files in different paces, and the Cacti Plugin hasn’t been built to support Ubuntu cacti install.
Invalid PHP_SELF path
The first telltale you will see is the “Invalid PHP_SELF Path” error message when you try to access your Cacti pages after patching. This is because a few of the $configs in global.php are wrongly pathed.
The Solution
Open up your global.php with your favourite editor. My global.php is located at /usr/share/cacti/site/include/. If you’re install is the default Ubuntu, it should be there too.
So, to get it working, you need to change the following lines in the global.php.
At line 104: $config["rra_path"] = $config["base_path"]."/rra"; change it to: $config["rra_path"] = "/var/lib/cacti/rra";
At line 128 where it says: $_SERVER["PHP_SELF"] change it to: basename($_SERVER["PHP_SELF"]) the whole line should say: if (!((is_file($_SERVER[”SCRIPT_FILENAME”])) && (substr_count($_SERVER[”SCRIPT_FILENAME”], basename($_SERVER[”PHP_SELF”]))))) {
At line 201: include($config["library_path"]."/adodb/adodb.inc.php"); change it to: include("/usr/share/php/adodb/adodb.inc.php");
Also, don’t forget to update (if you haven’t done so) the following, as stated in the Plugin install docs
On line 56 Change: $config[’url_path’] = ‘/’; to: $config[’url_path’] = ‘/cacti/’;
After this, try again, you should have your Cacti back in action. (Hopefully…)
- Codeigniter: Mixing segment-based URL with querystrings
- Cacti: Using Cacti to monitor web page loading - Part 1
- Cacti: Using Cacti to monitor web page loading - Part 2
- Codeigniter: Helpers, Plugins and Libraries
- Cacti: Using Cacti to monitor web page loading - Part 3






Thank you so much for this fix. I’m almost there. When I add in all the prepatched files, and make the above changes to /usr/share/cacti/site/include/global.php the site does come back…almost.
I lose all text formatting and graphics. All of the links on the left also have dropped the /cacti/ directory and are attempting to link the php files to the root of the directory.
If you have any recommendations, they are greatly welcomed. I will continue tweaking and post any updates as I am successful.
Thanks
I figured I’d find the culprit…
On line 56 Change:
$config[’url_path’] = ‘/’;
to:
$config[’url_path’] = ‘/cacti/’;
That did it!!!
Thanks for your hard work.
thanks for this lil snippet of help
however i had a bit of an issue adding the code you provide:
firstly 1 small typo
$config[”rra_path”] = “/var/lib/cacti/rra”;
this should read:
$config[”rra_path”] = “/var/lib/cacti/rra”;
secondly is line 128
i add what you provided but it appeard to give the error ‘unexpected { on line 128 so after looking at the line of code & taking in what it’s neighbouring lines contained i added an extra ) this helped fix the issue but if you would rather replace the entire line use this:
if (!((is_file($_SERVER[”SCRIPT_FILENAME”])) && (substr_count($_SERVER[”SCRIPT_FILENAME”], basename($_SERVER[”PHP_SELF”]))))) {
again thanks alot for giving me the spring board to fix this little bug
Thanks Tom and Brian for your comments. I’ve updated the post with your feedback.
I’m confused. I ran the patch and found this article with all the updates I need to make to global.php, but when I look at the lines, they are already in there and it still doesn’t work. The patch looked like it ran with no errors. Could I have another problem??
Gents
I am getring this error after following you quide
Parse error: syntax error, unexpected T_VARIABLE in /usr/share/cacti/site/include/global.php on line 107
Hi,
I did it all using patch…
But spine not worked after plugin arc. installed.
any idea?
I am running ubuntu 8.04 LTS and this didn’t work for my configuration of cacti 0.8.7b installed as a package.
The problem remains in the global.php and it looks like the regular expression on lines 86-87 are not always working and it breaks very quickly. I had to restart the apache server all the time.
In order to fix that temporary, I replaced them with static paths, I hope they will fix that in the next release.
#REMOVED LINES:
$config[”base_path”] = strtr(ereg_replace(”(.*)[\/\\]include”, “\\1″, dirname(__FILE__)), “\\”, “/”);
$config[”library_path”] = ereg_replace(”(.*[\/\\])include”, “\\1lib”, dirname(__FILE__));
#ADDED LINES:
$config[”base_path”] = ‘/usr/share/cacti/site’;
$config[”library_path”] = ‘/usr/share/cacti/site/lib’;
Excellent. I followed your instructions to the T and it worked. All my old data is still there