【问题标题】:How to set environment variable in MAMP?如何在 MAMP 中设置环境变量?
【发布时间】:2015-08-20 06:02:50
【问题描述】:

如何在 MAMP(3.3 版)中设置可以在我的 PHP 应用程序中使用的环境变量?

我已更新/Applications/MAMP/Library/bin/envvars_ and envvars-std_ file 并添加以下行:

# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#
# envvars-std - default environment variables for apachectl
#
# This file is generated from envvars-std.in
#
if test "x$DYLD_LIBRARY_PATH" != "x" ; then
  DYLD_LIBRARY_PATH="/Applications/MAMP/Library/lib:$DYLD_LIBRARY_PATH"
else
  DYLD_LIBRARY_PATH="/Applications/MAMP/Library/lib"
fi
export DYLD_LIBRARY_PATH

MY_TEST_DETAIL="foo"
export MY_TEST_DETAIL

#

我查看了 phpinfo(),但找不到 MY_TEST_DETAIL。

谁能告诉我我做错了什么? 提前致谢。

【问题讨论】:

  • 这个方法曾经在 MAMP 2.x 中工作

标签: php apache environment-variables mamp


【解决方案1】:

找到了解决方案。在/Applications/MAMP/conf/apache/httpd.conf 中添加了以下内容:

SetEnv MY_TEST_DETAIL foo

【讨论】:

    【解决方案2】:

    至少对于 MAMP PRO (version 3.5),您可以从菜单中找到并编辑您的 apache httpd.conf 文件。

    文件 -> 编辑模板 -> Apache -> httpd.conf

    ...您可以添加如下内容:

    SetEnv ENVIRONMENT development
    

    然后在 PHP 中你可以像这样获取环境变量:

    $env = getenv('ENVIRONMENT');
    
    if($env == "development") {
       $db_host = "localhost";
    }
    

    请注意,如果/当您更新或升级 MAMP 时,它可能会用较新的版本覆盖此 httpd.conf 文件。

    【讨论】:

      【解决方案3】:
      # This file is generated from envvars-std.in
      

      我不确定,但也许您没有更改好文件。

      【讨论】:

        猜你喜欢
        • 2012-06-30
        • 1970-01-01
        • 2019-07-02
        • 2014-09-29
        • 2016-06-27
        • 2012-08-03
        • 2017-07-31
        • 2015-08-01
        相关资源
        最近更新 更多