在AWS Elastic Beanstalk上部署后运行PHP脚本

Nic*_*ons 2 magento amazon-elastic-beanstalk

我已经创建了一个PHP脚本,它为Magento生成一个local.xml文件,其中包含所需的数据库设置和凭据.我需要在部署应用程序后运行它; 但我似乎无法找到一种方法.我的理解是我需要.config.ebextensions目录中创建一个文件.有人有解决方案吗?

小智 8

从技术上讲,约什是不正确的.根据文档(http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/customize-containers-ec2.html#customize-containers-format-commands):命令部分.."命令被处理按名称的字母顺序排列,它们在应用程序和Web服务器设置并提取应用程序版本文件之前运行."

我知道的是"在container_commands的命令在字母顺序被处理的"container_commands"部分最接近他们运行.应用程序和Web服务器已经设置和应用程序版本的文件已被提取之后,但之前部署了应用程序版本."

我不知道在部署后真正运行脚本的方法(这就是我在这里寻找答案的原因).


XuD*_*ing 6

Elastic Beanstalk将查看/ opt/elasticbeanstalk/hooks/appdeploy/post目录下的文件,以便在部署运行.

所以你可以利用这个并做:

commands:
  create_post_dir:
    command: "mkdir /opt/elasticbeanstalk/hooks/appdeploy/post"
    ignoreErrors: true
files:
  "/opt/elasticbeanstalk/hooks/appdeploy/post/job_after_deploy.sh":
    mode: "000755"
    owner: root
    group: root
    content: |
      #!/usr/bin/env bash
      /var/app/current
      ** run your php script here **

  • 没关系,通过在运行PHP脚本之前添加`source/opt/elasticbeanstalk/support/envvars`来解决环境变量问题. (2认同)