Coder Social home page Coder Social logo

alexander-schranz / aws-elastic-beanstalk-php-symfony-example Goto Github PK

View Code? Open in Web Editor NEW
10.0 3.0 4.0 20 KB

Example Elastibeanstalk PHP Symfony Files

Shell 100.00%
aws-elastic-beanstalk aws-elasticbeanstalk deployment doctrine symfony php redis

aws-elastic-beanstalk-php-symfony-example's Introduction

AWS Elasticbeansstalk PHP Symfony Example

This repository should help others how to deploy your Symfony application to AWS Elasticbeansstalk PHP instances.

Requires

  • Elasticbeanstalk instance
  • DB Instance
  • Configured ENV Variables (configured via AWS UI)
    • APP_ENV
    • DATABASE_URL
    • MESSENGER_TRANSPORT_DSN (if messenger is used)
    • MAILER_DSN (if mailer is used)
  • Gitlab ENV Variables (if gitlab is used for deployment, configured via Gitlab UI)
    • AWS_ACCESS_KEY_ID
    • AWS_SECRET_ACCESS_KEY

Features

Feedback welcome

You did struggle with something let me know. So we can here add more faqs to help others avoiding same problems.

FAQ

Deploy locally

You can deploy when you have eb installed (MacOS brew install awsebcli) via:

eb init "Your Application Name" --platform "PHP 8.0 running on 64bit Amazon Linux 2" --region=eu-central-1 --profile=eb-cli
eb deploy

Debug Deploy errors

You can use following command to debug deploy errors:

eb logs

The full logs you can download via the AWS Website. In my case following logs did help

  • eb-engine.log
  • cfn-init.log
  • cfn-init-cmd.log (this log file helped me find illegal syntax in my command scripts)

Forcing HTTPS

In the .platform/nginx/conf.d/elasticbeanstalk/nginx.conf it is possible to force https. Via:

    fastcgi_param HTTPS on;

I could not get it work via x-forwarded-* headers as the were not send to my instance.

Cronjob only on one Instance

If your applicaton is running with multiple instances it is maybe important that your cronjobs only run on one instance for this have a look at the following issue and example:

#1.

Permission denied install_supervisor

If you have problem to deploy with supervisor and have following in your cfn-init-cmd.log:

/bin/sh: .ebextensions/supervisor/setup.sh: Permission denied

It could be an error with the setup.sh not being executable so make it executable via:

chmod +x .ebextensions/supervisor/setup.sh: 

aws-elastic-beanstalk-php-symfony-example's People

Contributors

alexander-schranz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

aws-elastic-beanstalk-php-symfony-example's Issues

Run cronjob on a single instance

I got the following example from @t-richard to run cronjobs only on single instance:

# Source: https://github.com/awsdocs/elastic-beanstalk-samples/blob/master/configuration-files/aws-provided/instance-configuration/cron-leaderonly-linux.config
packages:
  yum:
    jq: []
files:
  "/usr/local/bin/test_cron.sh":
    mode: "000755"
    owner: root
    group: root
    content: |
      #!/bin/bash
      INSTANCE_ID=`curl http://169.254.169.254/latest/meta-data/instance-id 2>/dev/null`
      REGION=`curl -s http://169.254.169.254/latest/dynamic/instance-identity/document 2>/dev/null | jq -r .region`
      # Find the Auto Scaling Group name from the Elastic Beanstalk environment
      ASG=`aws ec2 describe-tags --filters "Name=resource-id,Values=$INSTANCE_ID" \
          --region $REGION --output json | jq -r '.[][] | select(.Key=="aws:autoscaling:groupName") | .Value'`
      # Find the first instance in the Auto Scaling Group
      FIRST=`aws autoscaling describe-auto-scaling-groups --auto-scaling-group-names $ASG \
          --region $REGION --output json | \
          jq -r '.AutoScalingGroups[].Instances[] | select(.LifecycleState=="InService") | .InstanceId' | sort | head -1`
      # If the instance ids are the same exit 0
      [ "$FIRST" = "$INSTANCE_ID" ]
  "/etc/cron.d/cronjobs":
    mode: "000644"
    owner: root
    group: root
    content: |
      * * * * * root /usr/local/bin/test_cron.sh && whatever command you need
commands:
  remove_old_cron:
    command: "rm -fr /etc/cron.d/cron_example.bak"
    ignoreErrors: true

Maybe similar adjustments would be needed to run the supervisor only on one instance.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.