I want to set environment variables in drush.yml
-
Locate or Create
drush.yml
: Find thedrush.yml
file in your Drush configuration directory. If it’s not there, create one. You might place it in the site-specific directory (sites/default/drush.yml
) or globally (~/.drush/drush.yml
). -
Edit
drush.yml
: Open the file in a text editor. Use a simple YAML syntax to define your environment variables:variables: MY_VARIABLE: 'my_value' ANOTHER_VARIABLE: 'another_value'
Replace
MY_VARIABLE
andANOTHER_VARIABLE
with your desired variable names and corresponding values. -
Save Changes: Save the
drush.yml
file.
Here’s an example:
variables:
DATABASE_URL: 'mysql://user:password@localhost/db_name'
MY_CUSTOM_VARIABLE: 'custom_value'
Once set, you can use these variables within Drush commands or scripts. If you need them more broadly, you can access them using PHP functions like getenv()
in your custom Drush commands or scripts.
Remember, while drush.yml
is specific to Drush configuration, for more general environment variables accessible system-wide, consider setting them at the system level or through tools like Docker.