tags:

views:

203

answers:

1

I've set in my custom.conf file in apache2 this:

SetEnv PATH $PATH:/opt/local/lib/mysql5/bin:/this-is-a-test

However it's not working. When I call:

$hey = shell_exec('env'." 2>&1"); var_dump($hey);

I get:

... PATH=/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin:/usr/X11/bin:/opt/local/bin

Can anyone help? I'm on Mac using Macports for my development environment. Thanks!

A: 

That seems awfully strange to me that you are trying to set the PATH from within Apache. Instead, you should be setting the PATH for your system. There are several ways to do this in Mac OS X:

User-specific
For a single user, you can edit ~/.profile and add:

export PATH="$PATH":/opt/local/lib/mysql5/bin:/this-is-a-test

Or you can create/edit ~/.MacOSX/environment.plist and define the PATH that way.

System-wide
On newer versions of Mac OS X, there is a file named "/etc/paths" and there is a folder named "/etc/paths.d" that allow you to extend the default paths. Basically, you would create a file in "/etc/paths.d" that lists all the paths that you wish to add to the default paths. On versions of Mac OS X that do not support this (you can tell based on whether "/usr/libexec/path_helper" exists), one can edit the default paths for all users by placing the export statement above in /etc/profile.

Michael Aaron Safyan
Michael, thanks for responding. Both my .profile and .bash_login files have the specified paths, but PHP running on Apache doesn't recognize them. I just tried the /etc/paths.d/ option, but that didn't seem to work either, do I have to restart the machine for those to take affect? I restarted apache - nothing.
TylerNZ
@TylerNZ, you need to close, then reopen the Terminal, and then restart Apache from within your environment in which those variables are defined.
Michael Aaron Safyan
@Michael - tried that, still nothing ... I think something specific needs to be done for either apache or the root user, which apache is running as?
TylerNZ
PHP shell_exec('env'); returns: DYLD_FALLBACK_LIBRARY_PATH=/opt/local/lib:TERM=xterm-colorSHELL=/bin/bashUSER=rootSUDO_USER=joeltSUDO_UID=501SSH_AUTH_SOCK=/tmp/launch-BAXRDR/Listeners__CF_USER_TEXT_ENCODING=0x0:0:0USERNAME=rootPATH=/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin:/usr/X11/bin:/opt/local/bin_=/usr/bin/envPWD=/Users/joelt/SitesLANG=en_US.UTF-8HOME=/Users/joeltSUDO_COMMAND=/opt/local/apache2/bin/apachectl restartSHLVL=2LOGNAME=rootDISPLAY=/tmp/launch-dNcZy6/org.x
TylerNZ
Hmmm, it seems that if you actually STOP and START apache, it fixed the issue. Simply RESTARTING did not do the trick. Weird.
TylerNZ