如何在MacOSX中将MacPorts添加到php-fpm的PATH

时间:2016-04-22 18:38:51

标签: php macos shell environment-variables macports

问题实际上是由php-fpm 5.6运行的PHP脚本,该脚本是从MacPorts安装的。

PHP代码system('echo $PATH') 当由php-fpm运行时,它返回

  

的/ usr / GNU / bin中:在/ usr / local / bin中:/ bin中:在/ usr / bin中:

cli中由bash运行时,它会返回

  

的/ opt / local / bin中:/选择/ local / sbin中:在/ usr / local / bin中:在/ usr / bin中:/ bin中:/ usr / sbin目录:/ sbin目录中:/ opt / local / bin中:/选择/ local / sbin中

system执行sh而非bash的命令,但MacPorts添加

  

export PATH =“/ opt / local / bin:/ opt / local / sbin:$ PATH”

~/.profilephp-fpmnobody而不是我当前的用户运行,因此导出不会影响php-fpm

我知道我可以将PATH从导出添加到/etc/profile/etc/paths。 但在MacPorts的情况下,哪种方式更安全。我不想破坏原生OS X功能或导致与MacPorts冲突。

修改

更改/etc/profile/etc/paths实际上没有帮助,system仍然看不到/opt/local/bin/中的程序:

  

sh:mysql:找不到命令

2 个答案:

答案 0 :(得分:0)

你走在正确的道路上(看看我在那里做了什么?)

编辑/etc/paths是解决方案,但您不仅仅是在寻找/opt/local/bin/mysql二进制文件(假设MySQL 5.5)存储在/opt/local/lib/mysql55/bin/mysql中。 MacPorts中有许多这样的路径:

/opt/local/bin/
/opt/local/sbin/
/opt/local/apache2/bin/
/opt/local/lib/mysql55/bin/
/opt/local/lib/php/pear/bin/

答案 1 :(得分:0)

唯一有效的方法是将env[PATH]中的/opt/local/etc/php56/php-fpm.conf设置为echo $PATH的结果