Skip to content

Set an environment variable without restarting the container #4658

Answered by MurzNN
MurzNN asked this question in Q&A
Discussion options

You must be logged in to vote

And here is a more detailed script, that applies the ENV value to the new terminals, and also to the current (if ran with source prefix):
cat /usr/local/bin/ddev-setenv:

#!/bin/bash

if [[ "$1" == *"="* ]]; then
  ENV=$(echo "$1" | cut -d '=' -f 1)
  VALUE=$(echo "$1" | cut -d '=' -f 2)
else
  ENV=$1
  VALUE=$2
fi

FILE_TERMINAL1=~/.profile
FILE_TERMINAL2=~/.bashrc
FILE_FPM=/etc/php/$DDEV_PHP_VERSION/fpm/pool.d/www.conf

# If arguments are empty.
if [ -z "$ENV" ]; then
  echo "Usage format:
$0 ENV value
or
$0 ENV=value
"
  exit
fi

# Removing the line if the value is empty, because php-fpm doesn't support empty values.
if [ -z "$VALUE" ]; then
  sed -i "s/^env\[$ENV\] = .*//" $FILE_FPM
else

Replies: 2 comments 7 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
7 replies
@MurzNN
Comment options

@rfay
Comment options

rfay Feb 17, 2023
Maintainer

@MurzNN
Comment options

@rfay
Comment options

rfay Feb 18, 2023
Maintainer

@MurzNN
Comment options

Answer selected by MurzNN
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants