Application Environment for application specific secrets
Currently to pass application specifics secrets (DBURL, APIKEYs, etc) the only options are to store them with your code (not best practice) or to edit the Application Settings / PHP Settings and manually configure them using php-fpm flag:
env[KEY] = VALUE
An interface such as Application Environment next/in to Application Settings which lists sets of 2 inputs (KEY, VALUE) which then generates an environment specific php.ini to be loaded by php-fpm will make it much easier for customers to configure these variables
-
Scott Euser commented
For comparison with other managed hosting services:
- Platform.sh: https://docs.platform.sh/create-apps/app-reference/single-runtime-image.html#variables - Provides a UI to manage env vars at server & application level. Each var at server level can be overridden at application level
- Pantheon: https://docs.pantheon.io/guides/environment-configuration/read-environment-config and https://github.com/pantheon-systems/terminus-secrets-manager-plugin - again provides high level + override per env.
-
Alvin Olavarrieta commented
Anyone know if this was every implemented on Cloudways?
-
cricgate commented
"Hey everyone! If you're as passionate about cricket as I am, I think you'll really enjoy my blog. I cover everything from match analyses to player profiles, and I always try to keep things fresh and interesting. Whether you're a die-hard fan or just getting into the sport, there's something for everyone. I'd love to hear your thoughts and connect with fellow cricket enthusiasts. Check it out at https://cricgate.com/! Looking forward to your feedback and discussions!"
-
NS Whatsapp commented
NS WhatsApp Mod APK is a modified version of the standard WhatsApp application. It is designed to offer users enhanced features and greater customization options that are not available in the official app. Developed by third-party developers, NS WhatsApp aims to provide a richer messaging experience by incorporating various tweaks and additional functionalities.
Download NS whatsapp with latest features: https://nswa.pro/id/ -
Michael Garlick commented
Application-level environment variables are 100% needed.
Putting API tokens and keys in the code is not good practice. Quite shocked that this is not already in place.
Please implement :)
-
Nate Cartwright commented
This is a basic feature of any web application platform. Often environment variables need to be specified to be used by CLI commands, for example for CraftCMS, which has many tools that are only available to CLI commands.
-
Anonymous commented
Hi, this feature is greatly needed. I've tried the suggested syntax, but it does not work
-
yoieh commented
I cant see how Im suppose to be able to set my env vars throw throw the php fpm settings when its not supported?
My lumen api uses .env to set the db connection and if you are using the staging management functionality the env vars needs to be applications specific other wise if i create a .env with my vars or a .htacces the wars will be over written when you push code to the live application and both live and staging will need to share the same database?
Im use to work with Azures application services where the applications env vars can be set as applications settings and allows locked to a applications while swapping.
I was adviced to write a php script that connects to Cloudways api makes the swap and then over writes my .env or .htaccess. But that feels like over kill to just be able to set my env vars. Especially if I will have many applications hosted here?
Ether Im missing or misunderstanding something because i cant be the only one in need for this to be set.
-
Adrian commented
@cloudways
RE: "As you rightly point out, this functionality is available and possible through the PHP Settings feature provided on the Platform."This seems to be false information. None of the following are allowed by the PHP FPM Settings editor:
;env[KEY] = VALUE
;VAR_NAME=VALUE
env[KEY] = VALUE
VAR_NAME=VALUEIt just says "One or more directive are not supported. Please choose from php_flag, php_admin_flag, php_value and php_admin_value."
How do we set variables here?
I have been advised to use the .bashrc file to load them. But then these are not application-specific and also .bashrc is not editable. Its permissions are set to 640 but vim says "Cannot open file for writing".
So that is not possible either.
It seems there is no solution because Cloudways have blocked every approach.
-
Adrian commented
It is frankly bizarre to me that there is no per-application environment file editor as we see in Laravel Forge. This would then be included in the virtual host for that application so the variables are available to it.
Putting API keys and so on in the source code is not an option.
This is a critical feature, and without it I will not be able to migrate my clients' applications to Cloudways as I had hoped.
-
Juan Alvarez commented
I've tried adding ;env[foo] = bar to PHP FPM settings but I get the following error:
One or more directive are not supported. Please choose from php_flag, php_admin_flag, php_value and php_admin_value.
-
Kit Grose commented
I agree with the other comments; it's valuable to be able to lean on environment variables for many operations that aren't performed by PHP (background tasks, .htaccess rules, etc.).
It would be nice to see a nicer input control for this, too, similar to how AWS does it: https://docs.aws.amazon.com/lambda/latest/dg/env_variables.html
-
Greg Martyn commented
What's missing for us is the ability to set vars that Apache sees. I'd like to be able to do this in our .htaccess:
RewriteRule ^ %{ENV:APP_URL}%{REQUEST_URI} [last,redirect=301]Without the ability to use variables, we need a separate .htaccess for each environment
-
Alex commented
Thank you for your response.
Actually after making this suggestion I ran into an more granular issue.
If one uses the PHP Settings section to configure those values - they will be only available to the PHP-FPM pool, but not to command line execution from cron jobs or manual.To get around this would be to have the php.ini settings file stored somewhere in the application file structure so one can pass it to the php executable via -c option
As to how much value it provides to users. I think truly it only provides an ease of access, but not an overall improvement.
-
AdminCloudways (Admin, Cloudways) commented
Hi Alex:
Thank you for your post.
As you rightly point out, this functionality is available and possible through the PHP Settings feature provided on the Platform. Have you faced any issues with getting it to work with environment variables?
By providing a new section, I see users having the following advantage:
a) A consolidated view of custom defined PHP env variables and their values.
b) Instead of users typing "env[VAR_NAME] = VAR_VALUE", they will be typing "VAR_NAME = VAR_VALUE" in the new section.I agree that it will bring some ease to users and provide a slightly cleaner alternative that what is available right now. However, I am trying to determine if, as a user, you will find that it will really provide value to users, since what this new section will achieve can already be achieved through the PHP Settings section?
Thanks.
Cloudways Team