4

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.

Sahil
  • 491
  • 2
  • 9
  • 18

3 Answers3

4

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

SetEnv MY_TEST_DETAIL foo
Sahil
  • 491
  • 2
  • 9
  • 18
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

MAMP PRO Apache template edit

...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.

martenc
  • 668
  • 6
  • 7
0
# This file is generated from envvars-std.in

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

Mindsers
  • 662
  • 8
  • 25