Awesome story!
A few remarks, in my humble opinion :)
First trick: root permissions
ARRRRRRG! This one made me react. It feels too much like an abuse of sudo. The reason is I feel I cannot hold in mind all the things that Apache does on my server. I can think of a quick fix. The way I would've done it is simply create a separate sudo user
appuser, and launch commands as this user with something like rsh (is there a better way to change users? I don't know.)
$ # 0 stands for localhost
$ rsh 0 -l appuser sudo /opt/myapp/mycommand -arg1 -arg2
This could've also avoided some problems that you had later on, like the Apache $PATH one.
Second trick: Configuring sudo
I'm not sure what you mean. I never configured sudo beyond adding users to the sudoers file. It'd be great if you could tell us more about it.
Third trick: Apache env variable
This one is particularly tricky. I love the idea of using httpd to launch the user. Yet setting up its env variables seems complicated. I never used it, but just like Ed says, you should grab your OS documentation and learn how httpd does that. If you want a quick hack, you could always do this
$ # On Debian 6 with bash.
$ type env
env is hashed (/usr/bin/env)
$ # You could do something like:
$ env PATH=$PATH:/opt/myapp sudo /opt/myapp/mycmd argv
env(1) available on most (if not all) modern unices. On Linux it's part of the GNU userland (package name 'coreutils').
In case you're wondering, the current running shell doesn't get affected by this change, which makes it a pretty solid solution, despite its hackish appearance. If you want more info, beware. On Linux, the man page of env is a bit empty, but it has a good 'info' page (it is a GNU utility after all). In short:
here's the command to get help with env:
$ info coreutils 'env invocation'
I really recommend you read it, it will save you a lot of headaches for next time.
Fourth trick: No HTML
This one is my favorite. It's what I call a very useful hack. It has just one downside is that you cannot assume cross browser compatibility, especially for future upgrades. Since it's a non standard feature, it might (I said _might_) come back and bite you in the derriere. Yet this is not a big issue, and if it means that you avoided having to write annoying HTML, then hell yeah!
Finally, it seems from the description that you maintain a legacy system dragging a lot of old burdens (you have to be root, use cgi-bin, ...) . It sounds cool. Can you give us a technical description of your parc?
Leaving you with the
obligatory xkcd reference.