Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run PHP script after deployment on AWS Elastic Beanstalk

I've created a PHP script that generates a local.xml file for Magento with the required database settings and credentials. I need to run this after the application is deployed; however I cannot seem to figure out a way to do so. My understanding is that I need to create a .config file inside of a .ebextensions directory. Anyone have a solution?

like image 880
Nick Parsons Avatar asked Feb 13 '26 19:02

Nick Parsons


2 Answers

Technically Josh is not correct. According to the documentation (http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/customize-containers-ec2.html#customize-containers-format-commands): the commands section .. "The commands are processed in alphabetical order by name, and they run before the application and web server are set up and the application version file is extracted."

The closest I am aware of is the "container_commands" section which "The commands in container_commands are processed in alphabetical order by name. They run after the application and web server have been set up and the application version file has been extracted, but before the application version is deployed."

I don't know of a way to truly run a script post deployment (which is why I was here looking for that answer).

like image 70
jpirkey Avatar answered Feb 17 '26 02:02

jpirkey


Elastic Beanstalk will look files under /opt/elasticbeanstalk/hooks/appdeploy/post directory to run after deployment.

So you can make use of this and do:

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 **
like image 20
XuDing Avatar answered Feb 17 '26 02:02

XuDing



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!