【问题标题】:Changing the Homebrew Apache PATH variable更改 Homebrew Apache PATH 变量
【发布时间】:2019-01-09 17:24:33
【问题描述】:

我最近通过 Homebrew 在我的 Mac 上安装了 Apache 2.4。 (我之前使用的是 Apple 提供的 Apache。)

在 PHP 脚本中,我在 /usr/local/bin 中的可执行文件上调用 Exec(x),但它失败了,因为 /usr/local/bin 未包含在 Apache 的 PATH 环境变量中。运行 phpinfo() 显示 PATH 是 /usr/bin:/bin:/usr/sbin:/sbin。

我之前已将 /usr/local/bin 包含在 /System/Library/LaunchDaemons/org.apache.httpd.plist 中,如 here 所述,但它不再有效,我想是因为我使用的是由自制。

我的 shell $PATH 包含许多目录,包括 /usr/local/bin,所以不是这样。

我宁愿不使用绝对路径调用 Exec,因为我需要在可执行文件位于不同路径的多个环境中运行它。

如何修改 Homebrew Apache 的 PATH 变量?谢谢!

【问题讨论】:

    标签: macos apache homebrew


    【解决方案1】:

    我找到了答案here

    要在随 Homebrew 一起安装 Apache 时更改 Apache 环境变量,请编辑位于 /usr/local/Cellar/httpd24/your version of Apache/ 中的 homebrew.mxcl.httpd24.plist 文件。

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"     "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <dict>
      <key>Label</key>
      <string>homebrew.mxcl.httpd24</string>
      <!-- add this -->
      <key>EnvironmentVariables</key>
      <dict>
       <key>PATH</key>
       <string>/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin</string>
      </dict>
      <!-- end add -->
      <key>ProgramArguments</key>
      <array>
        <string>/usr/local/opt/httpd24/bin/httpd</string>
        <string>-D</string>
        <string>FOREGROUND</string>
      </array>
      <key>RunAtLoad</key>
      <true/>
    </dict>
    </plist>
    

    然后重新启动 Apache。

    【讨论】:

      猜你喜欢
      • 2011-11-07
      • 2018-05-15
      • 1970-01-01
      • 2012-05-07
      • 2014-01-11
      • 2021-05-06
      • 1970-01-01
      • 2011-04-19
      相关资源
      最近更新 更多