sudo environment setting?

Hi, first post. As the nick suggests I'm a Unix noob, but I'm doing everything I can to learn fast...job requirement. These forums have been a huge help so far.

I have a server running HP-UX 11.23b with Apache/2.0.59 HP-UX_Apache-based_Web_Server.

Apache is not installed in the default location and an issue (not highly important but irritating) has popped up suddenly. No one thus far has a clue how to fix it.

It only involves invoking some Apache commands using sudo. This environment variable disappears (LD_LIBRARY_PATH=/web/app/hpws/apache/lib) when using sudo. For instance, type env at the command line and that variable is displayed in the output. Type sudo env at the command line and that environment variable doesn't exist in the output. I've checked and it's set in the /etc/profile and I've even gone so far as to set it in my .profile file, nothing works when using the sudo command.

My question is this, does anyone know how to set the system environment so that all users have the variable set when they use the sudo command without having to go through a bunch of commands to set it when they need it?

Any help is appreciated.

When you sudo to a different user (say root):

sudo su

This wont set up that user's environment. If you:

sudo su -

That will. However, when you just want to run a command, I don't believe there is a way to have it configure the environment automatically. However, you can set LD_LIBRARY_PATH using the envvars file. In your install directory:

<my install path>/bin/envvars

It'll probably already have LD_LIBRARY_PATH in there, so just append your lib directory. If you need to have that lib dir passed to cgi-bin scripts and the like, you'll need to edit your httpd.conf file and add this line:

PassEnv LD_LIBRARY_PATH

I know some systems don't have an envvars file, I'm used to working on Solaris, so if it's not there, try creating it. Otherwise you can always create a wrapper script which sets the path, then calls apachectl...

Thank you very much for the information. Never considered the httpd.conf file but your suggestion did fix one issue I was having.

The envvars file did have the correct variable path statement in it which still begs the question as to why issuing a sudo <any command> doesn't pick up any environment variables. Unless it's the fact that even though your telling the system to issue the command as root, you're not initiating root user and the environment settings like you would if you switch to root using sudo su - root.

I believe sudo has security problems with LD_LIBRARY_PATH and some other envrionment variables. According to the man page for sudo on 11.23 - it removes that environment variable.

The easiest way around that is to relink the executable file using the -L parameter, so that ld looks in the right path for libraries.