如何在MAMP中设置环境变量?

时间:2015-08-20 06:02:51

标签: php apache environment-variables mamp

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

我已更新/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。

任何人都可以告诉我,我做错了什么? 提前谢谢。

3 个答案:

答案 0 :(得分:3)

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

SetEnv MY_TEST_DETAIL foo

答案 1 :(得分:1)

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

档案 - >编辑模板 - > Apache - >的httpd.conf

MAMP PRO Apache template edit

...你可以添加这样的东西:

SetEnv ENVIRONMENT development

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

$env = getenv('ENVIRONMENT');

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

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

答案 2 :(得分:0)

# This file is generated from envvars-std.in

我不确定,但也许你没有改变好文件。