title: How to Export Environment Variable From Script in PHP Docker Entrypoint
body: <p>I have a script that grabs variables and export it as environment variable. And I also have PHP-based docker for my web application. I tried to execute the script in the <code>docker-php-entrypoint</code> but the environment variable is not loaded.</p>
  <p>The Dockerfile is like below.</p>
  <pre><code>FROM php:7.2-apache
  
  COPY docker-php-entrypoint /usr/local/bin/
  COPY load_parameter_store.sh /opt/
  COPY src/ /var/www/html/
  </code></pre>
  <p>This is the <code>docker-php-entrypoint</code> content. It runs a script <code>load_parameter_store.sh</code>.</p>
  <pre><code>#!/bin/sh
  set -e
  
  /opt/load_parameter_store.sh
  
  # first arg is `-f` or `--some-option`
  if [ &quot;${1#-}&quot; != &quot;$1&quot; ]; then
      set -- php &quot;$@&quot;
  fi
  
  exec &quot;$@&quot;
  </code></pre>
  <p>And this is the script itself</p>
  <pre><code>EXPORT_STATEMENT='export MY_VARIABLE=FooBar' #Will be loaded from AWS SSM Parameter Store
  
  eval $EXPORT_STATEMENT
  </code></pre>
  <p>I have a PHP web script that shows the environment variable.</p>
  <pre><code>&lt;?php
  
  $var = $_ENV['MY_VARIABLE'];
  echo &quot;Hello World {$var}&quot;;
  </code></pre>
  <p>The end goal is that I would like the PHP shows <code>Hello World FooBar</code> but what I get is just <code>Hello World</code>. It means that the variable is not loaded.</p>
  <p>What should I do to fix this?</p>