Is there a way to read variables from the local .env file ? #3479
Unanswered
HassanZahirnia
asked this question in
Help needed
Replies: 2 comments 1 reply
-
|
Yes, via Dotenv. |
Beta Was this translation helpful? Give feedback.
1 reply
-
|
Hi, This happens when you install deployer.org using the binary or globally. In the deployer folder run: composer require deployer/deployer
composer require vlucas/phpdotenvExample code: require __DIR__ . '/vendor/autoload.php';
$dotenv = \Dotenv\Dotenv::createImmutable(__DIR__);
$dotenv->safeLoad();
set('slack_webhook', getenv('SLACK_WEBHOOK'));
set('slack_channel', '#dev');
set('slack_title', 'Deployment');
set('slack_success_text', 'Deploy successful');
set('slack_failure_text', 'Deploy failed');This works, but I couldn't get it working with optional variables: if(getenv('SLACK_WEBHOOK')){
set('slack_webhook', getenv('SLACK_WEBHOOK'));
// ...
}The notification is never sent. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I'd rather not have my host configurations such as host name, port, username, paths, etc... in the
deploy.phpand I prefer having them in a config file that is gitignored.I wonder if there is a way to read variables from a
.envfile ?Beta Was this translation helpful? Give feedback.
All reactions