10

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!

joelataylor
  • 193
  • 1
  • 4
  • 13

4 Answers4

8

for ubuntu server, in /etc/apache2/envvars, for centos server, in /etc/sysconfig/httpd, to add:

export PATH=<your php cli path>

and restart apache

diyism
  • 12,477
  • 5
  • 46
  • 46
3

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
  • 93,612
  • 16
  • 138
  • 200
  • 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. – joelataylor May 14 '10 at 21:40
  • @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 May 14 '10 at 21:59
  • tried that, still nothing ... I think something specific needs to be done for either apache or the root user, which apache is running as? – joelataylor May 14 '10 at 22:07
  • PHP shell_exec('env'); returns: DYLD_FALLBACK_LIBRARY_PATH=/opt/local/lib: TERM=xterm-color SHELL=/bin/bash USER=root SUDO_USER=joelt SUDO_UID=501 SSH_AUTH_SOCK=/tmp/launch-BAXRDR/Listeners __CF_USER_TEXT_ENCODING=0x0:0:0 USERNAME=root 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 _=/usr/bin/env PWD=/Users/joelt/Sites LANG=en_US.UTF-8 HOME=/Users/joelt SUDO_COMMAND=/opt/local/apache2/bin/apachectl restart SHLVL=2 LOGNAME=root DISPLAY=/tmp/launch-dNcZy6/org.x – joelataylor May 14 '10 at 22:18
  • Hmmm, it seems that if you actually STOP and START apache, it fixed the issue. Simply RESTARTING did not do the trick. Weird. – joelataylor May 14 '10 at 23:35
  • Unfortunately, neither of those ways have worked for me. I'm running OS X Yosemite. I've tried either with user-specific or system-wide. Any ideas? – Piotr Czyż Oct 21 '16 at 15:31
0

This question is old, but in case it helps others, if you are using Windows with mod_fcgid check if you have the FcgidInitialEnv set in your httpd.conf, and remove it to adopt the System PATH.

Gustavo Morales
  • 2,614
  • 9
  • 29
  • 37
Dan
  • 36
  • 2
0

Macports Apache 2.4 install

The only way I have found to get this to stick on a reboot is to edit the macports apache2.plist. Steps I took:

1.sudo /opt/local/sbin/apachectl stop

2.Edit plist: /opt/local/etc/LaunchDaemons/org.macports.apache2/org.macports.apache2.plist

And add:

<key>EnvironmentVariables</key>
<dict>
    <key>PATH</key>
    <string>/usr/bin:/bin:/usr/sbin:/sbin:{add paths here}</string>
</dict>

3.sudo port unload apache2

4.sudo port load apache2

5.sudo /opt/local/sbin/apachectl start

Paths stick on a reboot. However the plist will probably be wiped on the next macports update I do.

EDIT : And this proved to be true. I upgraded to Mojave with an associated macports update, and had to re-apply the steps above