How to set environment variable in MAMP?

a 夏天 提交于 2019-12-21 20:47:30

问题


How to set environment variable in MAMP(version 3.3) which can i use in my PHP application?

I have updated /Applications/MAMP/Library/bin/envvars_ and envvars-std_ file and add following lines:

# 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

#

I have looked into phpinfo() and not able to find MY_TEST_DETAIL.

Can anyone please tell me what am I doing wrong? Thanks in advance.


回答1:


found the solution. In /Applications/MAMP/conf/apache/httpd.conf added following:

SetEnv MY_TEST_DETAIL foo



回答2:


At least for MAMP PRO (version 3.5) from the menu you could find and edit your apache httpd.conf file.

File -> Edit Template -> Apache -> httpd.conf

...you could add something like this:

SetEnv ENVIRONMENT development

And then in PHP you can get the environmental variable like so:

$env = getenv('ENVIRONMENT');

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

Just be mindful that if/when you update or upgrade MAMP it'll likely overwrite this httpd.conf file with a newer verion.




回答3:


# This file is generated from envvars-std.in

I am not sure but maybe you haven't changed the good file.



来源:https://stackoverflow.com/questions/32110634/how-to-set-environment-variable-in-mamp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!