Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/273.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 将shell命令的输出传递到inside.env文件_Php_Amazon Web Services - Fatal编程技术网

Php 将shell命令的输出传递到inside.env文件

Php 将shell命令的输出传递到inside.env文件,php,amazon-web-services,Php,Amazon Web Services,我有一个php应用程序的.env文件。内容与此类似: #define env #dev,stage,prod env=stage http="https://" #define debug debug=true debug_level=2 #db mysql_host=staging-rds.cvexrtrtr1.us-east-2.rds.amazonaws.com mysql_port=3306 mysql_username=dev mysql_password=&

我有一个php应用程序的.env文件。内容与此类似:

#define env
#dev,stage,prod
env=stage

http="https://"

#define debug
debug=true
debug_level=2

#db
mysql_host=staging-rds.cvexrtrtr1.us-east-2.rds.amazonaws.com
mysql_port=3306
mysql_username=dev
mysql_password="existing!secret"
我想在AWS paramater存储中存储mysql_密码的秘密。目标是不让值
存在!机密
暴露于环境变量或任何访问机器的人, 基本上,我希望bash命令的输出与下面的类似,直接在.env文件中传递:

export DB_PASSWORD=$(aws ssm get-parameter \
  --name "secret-for-the-password" \
  --with-decryption \
  | jq -r '.Parameter.Value')
基本上可以将此命令的输出传递到.env文件吗?输出应类似于:

#define env
#dev,stage,prod
env=stage

http="https://"

#define debug
debug=true
debug_level=2

#db
mysql_host=staging-rds.cvexrtrtr1.us-east-2.rds.amazonaws.com
mysql_port=3306
mysql_username=dev
mysql_password="$(aws ssm get-parameter \
  --name "secret-for-the-password" \
  --with-decryption \
  | jq -r '.Parameter.Value')"

将secret存储为环境变量似乎是更好的选择,但如果这更适合您的需要,您可以使用
exec
运行bash代码,例如:

<?php

$mysql_password = "aws ssm get-parameter \
--name \"secret-for-the-password\" \
--with-decryption \
| jq -r '.Parameter.Value'";

$retval = exec($mysql_password);

echo $retval;

ok。那么在我的.env文件中,我应该为
mysql\u password=
提到什么值呢?基本上,我如何将这个PHP代码绑定回我的.env文件?mysql\u password=“aws ssm get parameter \--name \”secret for the password \'--with decryption \|jq-r'.parameter.Value';好的,谢谢。让我试试看。我不确定是否可以在
.env
中直接传递shell命令