Adding custom environment variables
Overview
Environment variables contain a name and value, and provide a simple way to share configuration settings between multiple applications and processes in Linux. For example, Cloud 66 creates environment variables for your database server address, which can be referenced in your code. This has numerous benefits:
- Your environments can use different environment-specific configurations with less manual intervention
- These values may change, so setting them as variables makes updating them simpler to update
- You don’t need to commit sensitive information to your Git repository
By default Maestro creates and manages the minimum environment variables required to run your application. This guide will walk you through how to add custom environment variables to your Maestro application, and how to edit existing variables.
What you’ll need
Before you start, please check you have the following:
- A Cloud 66 Account — If you don’t already have one, sign up for a Cloud 66 account. You’ll get free unlimited access to all products for 4 weeks.
- An existing application set up in Maestro — To make the most of this tutorial you need to have an app already set up in Maestro. Follow our Getting Started guide if you’re not sure how to do this.
Adding an environmental variable
To add a custom environment variable to your application:
- Open the Application Overview from your Dashboard
- Click on Environment Variables in the Application panel on the right of the screen
- Scroll down to the Your Custom Variables section
- Add the key
FOO
and the valueBAR
(don’t worry these are dummy entries and won’t actually do anything) - Click Save Changes
- New environment variables are only applied to your application server(s) when you deploy. Do that now by clicking the Build / Deploy button.
Testing your change
The best way to check whether your new variable has been applied to your server is to log into it via SSH. Cloud 66 Toolbelt is the quickest way to do this.
Once you are connected to your server, enter this command printenv FOO
. The server will responed with BAR
. If it does not, check you have followed all the steps above.
Editing an existing variable
You can edit / update any custom variables you have added to Maestro, as well as some of the default variables created by Maestro. A good example would be changing the password for your database server.
To do this:
- Open the Application Overview from your Dashboard
- Click on Configuration in the Application panel on the right of the screen
- Find the key you’d like to change, for example
MYSQL_PASSWORD
and update the value - Save and redeploy as you did above
You can test this by accessing your server via SSH using Cloud 66 Toolbelt and logging into MySQL with the new password.
Caution
Updating default environment variables can cause an application to break unless it has been coded to cope with such changes. Proceed carefully!
What’s next?
- Learn more about managing environment variables via Maestro, including how to reference variables in other applications.
- Learn how to customise the configuration of your application’s components.