AWS Elastic Beanstalk: Running Cron.d script, missing Environment Variables(AWS Elastic Beanstalk:运行 Cron.d 脚本,缺少环境变量)
问题描述
我正在尝试运行由 cron 脚本(在 cron.d 中)触发的 PHP 脚本.该脚本已正确触发,但缺少存储在 $_SERVER 超全局变量中的 Elastic Beanstalk环境变量".该脚本目前以用户root"身份运行,但它不在具有环境变量的同一环境中.变量设置正确,如果我从完整的 shell 运行脚本,它运行得很好.
I'm trying to run a PHP script that is triggered by a cron script (in cron.d). The script is triggered properly but it is missing the Elastic Beanstalk "Environment Variables" that are stored in the $_SERVER superglobal. The script is being run as the user "root" for now, but it's not in the same environment that has the environment variables. The variables are set correctly, if I run the script from a full shell it runs just fine.
这些变量的导出"在哪里?他们在哪里设置?我在/etc/apache/conf.d/aws_env.conf 中找到了 Apache 的 SetEnvs.我在用户的 .bashrc、.bash_profile 等文件中找不到任何内容.有解决方法吗?有更好的方法吗?
Where are the "exports" for these variables? Where do they get set? I found the SetEnvs for Apache in /etc/apache/conf.d/aws_env.conf. I can't find anything in the user's .bashrc, .bash_profile, etc. Is there a workaround? A better way to do this?
谢谢.
推荐答案
我刚刚发现这个,使用
grep -r "export MY_VAR" /
亚马逊似乎不时移动文件位置.当前位置是:
Amazon seems to move the file location from time to time. Current location is:
/opt/elasticbeanstalk/support/envvars
所以我想我会在调用我的 php 脚本之前在我的脚本中包含 (source [file path]) .似乎仍然是一种时髦的做事方式.我仍在寻找更好的解决方案.
So I think I'll just include (source [file path]) that in my script before calling my php script. Still seems like a funky way to do things. I'm still in for better solutions.
我通过 cron 触发的 bash 脚本运行 PHP.所以要设置环境,我会做这样的事情:
I was running PHP via bash script triggered by cron. So to setup the environment, I would do something like this:
#!/bin/bash
source /opt/elasticbeanstalk/support/envvars
php -f my-script.php
有关 PHP 解决方案,请参阅下面@userid53 的回答.
See @userid53's answer below for PHP solution.
这篇关于AWS Elastic Beanstalk:运行 Cron.d 脚本,缺少环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:AWS Elastic Beanstalk:运行 Cron.d 脚本,缺少环境变量
基础教程推荐
- PHP 守护进程/worker 环境 2022-01-01
- Doctrine 2 - 在多对多关系中记录更改 2022-01-01
- 使用 PDO 转义列名 2021-01-01
- 在 CakePHP 2.0 中使用 Html Helper 时未定义的变量 2021-01-01
- 如何在 Symfony 和 Doctrine 中实现多对多和一对多? 2022-01-01
- phpmyadmin 错误“#1062 - 密钥 1 的重复条目‘1’" 2022-01-01
- 找不到类“AppHttpControllersDB",我也无法使用新模型 2022-01-01
- 在 yii2 中迁移时出现异常“找不到驱动程序" 2022-01-01
- HTTP 与 FTP 上传 2021-01-01
- 如何在 XAMPP 上启用 mysqli? 2021-01-01