开发者

how to set the system $PATH outside of users .bash_profile on OSX for an added PHP version you installed

Ok so here is my problem. I am trying to write a php script that will run the following type of command.

exec("$(which php) -f /path/to/script.php >> /path/to/log.log 2>&1 &");

The problem is, I am running OSX 10.5 leopard and using the Entropy PHP package. This creates php under /usr/local/php5/bin. The 开发者_C百科normal php that is installed with OSX in under /usr/bin. So when PHP executes this command it is using the wrong PHP executable. Now I know how to change the $PATH in my .bash_profile by adding it to the begining of the $PATH so that the system takes the PHP I want other then the default PHP. The problem is, when running the php from a script it doesn't do it under my user. So then it doesn't have the updated $PATH settings.

I have also looked into setting it in /etc/paths and etc/paths.d/ but these both append the path to the end, I need it to append to the beginning so that my script will use the right PHP executable.

I know I probably could run another exec command and set the path but this is only a local environment issue and when the code goes to production I won't need this set.


One option is to set the global path for all users. See this answer for a few examples.

For example, if the user running the command is using bash as its shell you may edit /etc/bashrc adding a line like:

export PATH="$PATH:/more/paths:/

Another option is to modify /etc/launchd.conf (note that it does not exist on Leopard by default and expects csh setenv syntax)


Have you tried executing this before your exec function:

$my_new_path = '/usr/local/php5/bin';
putenv( "PATH=" . $my_new_path . PATH_SEPARATOR . getenv('PATH') );

//then run your exec() call


IF i were you i would make a wrapper script specifically for exec and shell invocation:

#!/usr/bin/env php
<?php 

include('/path/to/script.php');

This way you can use the environment variable that points to php, which will work on the majority of nix systems.

Now that still doesnt get you set right on your OS X install for that you are going to have hardcode the path or follow the answer nimrodm linked to.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜