I have a PHP app and I would like to host staging, demo, and production servers from one instance on Linode. The challenge I am running into is loading different environment variables for each server.
I have created multiple .conf files in /etc/apache2/sites-available/ which look like this:
<VirtualHost *:80>
ServerAdmin [email protected]
ServerName stag.example.com
ServerAlias stag.example.com
DocumentRoot /var/www/example-app/public
ErrorLog /var/www/example-app/writable/logs/errors.stag.log
CustomLog /var/www/example-app/writable/logs/access.stag.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =stag.example.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
I have tried creating .sh files for each server in the /etc/profile.d/ directory that include all the environment variables, which look like this:
export ENV1="abc"
export ENV2="def"
But I don't know how I can load that file in the .conf file. I have also tried explicitly setting an APP_ENV variable in the .conf (i.e. SetEnv APP_ENV staging
). I would then check the APP_ENV variable in the PHP code (i.e. getenv("APP_ENV")
) and based on that, I could then read the correct .sh file and load the environment variables in that file into $_ENV. However, for some reason, the APP_ENV variable is not showing up when I retrieve all the environment variables in my PHP code (i.e. print_r getenv()
). When I do that, only the variables set in the /etc/apache2/envvars are listed.
I am new to Ubuntu and Linode (previously, I only used managed servers), so it is possible I am missing something simple, so any help you can provide, would be much appreciated.