{"id":19143167,"url":"https://github.com/devenes/terraform-php-beanstalk","last_synced_at":"2026-04-09T22:48:29.725Z","repository":{"id":43081368,"uuid":"471787499","full_name":"devenes/terraform-php-beanstalk","owner":"devenes","description":"Deployment of a PHP Web App on AWS Elastic Beanstalk with Terraform and GitHub Actions","archived":false,"fork":false,"pushed_at":"2022-03-19T23:38:54.000Z","size":34,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-03T15:44:00.705Z","etag":null,"topics":["aws","elastic-beanstalk","elastic-beanstalk-applications","elastic-beanstalk-environments","elastic-beanstalk-worker","elasticbeanstalk","github-actions","php","terraform"],"latest_commit_sha":null,"homepage":"https://devenes.github.io/terraform-php-beanstalk/","language":"HCL","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/devenes.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-03-19T19:00:46.000Z","updated_at":"2022-04-19T20:44:48.000Z","dependencies_parsed_at":"2022-08-23T16:31:21.305Z","dependency_job_id":null,"html_url":"https://github.com/devenes/terraform-php-beanstalk","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devenes%2Fterraform-php-beanstalk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devenes%2Fterraform-php-beanstalk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devenes%2Fterraform-php-beanstalk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devenes%2Fterraform-php-beanstalk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/devenes","download_url":"https://codeload.github.com/devenes/terraform-php-beanstalk/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240224095,"owners_count":19767703,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aws","elastic-beanstalk","elastic-beanstalk-applications","elastic-beanstalk-environments","elastic-beanstalk-worker","elasticbeanstalk","github-actions","php","terraform"],"created_at":"2024-11-09T07:29:48.890Z","updated_at":"2026-04-09T22:48:29.661Z","avatar_url":"https://github.com/devenes.png","language":"HCL","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PHP Elastic Beanstalk Deployment with Terraform\n\n\u003cimg src=\"https://img.shields.io/badge/AWS-ElasticBeanstalk-orange.svg?style=flat-square\" alt=\"AWS\" /\u003e \u003cimg src=\"https://img.shields.io/badge/PHP-8.0-blue.svg?style=flat-square\" alt=\"PHP Version\" /\u003e \u003cimg src=\"https://img.shields.io/badge/Terraform-1.1.7-purple.svg?style=flat-square\" alt=\"Terraform\" /\u003e \u003cimg src=\"https://img.shields.io/badge/Amazon Linux 2-3.3.11-green.svg?style=flat-square\" alt=\"AWS\" /\u003e\n\n\u003cimg src=\"https://miro.medium.com/max/1200/1*LI9WOn1yLbaNXsEgs7H9dg.png\" alt=\"diagram\" /\u003e\n\n## Getting Started with the Sources\n\nTerraform is a tool for building and managing infrastructure as code. It is a declarative,\nprogrammatic, and portable way to create, destroy, and update infrastructure.\n\nIt helps us to define S3 Buckets, IAM Roles, EC2 Instances, and more.\nWe use S3 Buckets to store our application code files.\nAnd we use IAM Roles to give permissions to our EC2 Instances.\n\nElastic Beanstalk is a service that makes it easy to deploy, manage, and scale\napplications on Amazon's Elastic Cloud Compute Service.\n\nElastic Beanstalk creates the application environment with code stored in S3 buckets and makes it run on EC2 instances as application environments.\n\n- You need to create an IAM role for the application. You can create an IAM role by following the instructions in the [AWS IAM Roles](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles.html) section of the AWS IAM User Guide. IAM roles are used to authorize Terraform's operations. IAM role you create for this operations should have the S3, EC2, Elastic Beanstalk permissions.\n\nAfter you create IAM user and policy you need to get its access key and secret key. And define them in GitHub Secrets as the environment variables. Replace your access key and secret key with your own access key and secret key with the following format:\n\n```\nAWS_ACCESS_KEY_ID\n```\n\n```\nAWS_SECRET_ACCESS_KEY\n```\n\n## AWS Elastic Beanstalk\n\nAdd the existing Security Group to your AWS Elastic Beanstalk environment to allow access to the Elastic Beanstalk environment and the instances in the environment.\n\n```\n  setting {\n    namespace = \"aws:autoscaling:launchconfiguration\" # Define namespace for environment settings\n    name      = \"SecurityGroups\"                      # Define name of the environment setting\n    value     = \"devsec\"                              # Define name of the security group to be used\n  }\n```\n\n## SSHSourceRestriction\n\nUsed to lock down SSH access to an environment. For example, you can lock down SSH access to the EC2 instances so that only a bastion host can access the instances in the private subnet.\n\nThis string takes the following form:\n\n`protocol`, `fromPort`, `toPort`, `source_restriction`\n\n- `protocol`\n\n  - The protocol for the ingress rule.\n\n- `fromPort`\n\n  - The starting port number.\n\n- `toPort`\n\n  - The ending port number.\n\n- `source_restriction`\n\n  - The CIDR range or the name of a security group that traffic must route through.. To specify a security group from another account (EC2-Classic only, must be in the same Region), include the account ID before the security group name. Use the following format:\n    `other_account_id`/`security_group_name`\n\nIf you use Amazon Virtual Private Cloud (Amazon VPC) with Elastic Beanstalk so that your instances are launched within a virtual private cloud (VPC), specify a security group ID instead of a security group name.\n\nExample: `tcp, 22, 22, 54.240.196.185/32`\n\nExample: `tcp, 22, 22, my-security-group`\n\nExample (EC2-Classic): `tcp, 22, 22, 123456789012/their-security-group`\n\nExample (VPC): `tcp, 22, 22, sg-903004f8`\n\n- Note: We don't create a new VPC in this template, so you don't need to specify the VPC ID and Security Group ID.\n\n## Configuring SSH access to the Elastic Beanstalk environment:\n\n```\n  setting {\n    namespace = \"aws:autoscaling:launchconfiguration\" # Define namespace for environment settings\n    name      = \"SSHSourceRestriction\"                # Define name of the environment setting\n    value     = \"tcp, 22, 22, 0.0.0.0/0\"              # Define value of the environment setting\n  }\n```\n\n## Defining Solution Stack\n\nYou need to define your application version number and platform operating system version number on AWS that you want to use for deployment under `aws_elastic_beanstalk_environment` source section in main Terraform file called `main.tf` in this project.\n\n- Deployment fails in Terraform stages when you type a value for `solution_stack_name` if it is not valid or not supported in Amazon Web Services (AWS).\n\n- For example, if you type `64bit Amazon Linux 2 running PHP 8.0` for `solution_stack_name` in `aws_elastic_beanstalk_environment` source section in main Terraform file called `main.tf` in this project, Terraform will fail in stages.\n\n```\nsolution_stack_name = \"64bit Amazon Linux 2 v3.3.11 running PHP 8.0\"\ndescription = \"environment for web app\"\n```\n\n## Automate Terraform Deployment with GitHub Actions\n\nWhen you create GitHub Action workflow, you can run `terraform apply` and `terraform destroy` stages automatically by pushing your code to GitHub repository. You can seperate stages with adding the following commands to your GitHub Action workflow:\n\nYou will be able to run `terraform apply` command when you push your code to the `main` branch:\n\n```\n- name: Terraform Apply\n  if: github.ref == 'refs/heads/main'\n  id: apply\n  run: terraform apply\n```\n\nYou will be able to run `terraform destroy` command when you push your code to the `destroy` branch:\n\n```\n- name: Terraform destroy\n  if: github.ref == 'refs/heads/destroy'\n  id: destroy\n  run: terraform destroy\n```\n\n## Define Terraform stages in GitHub Actions workflow:\n\nYou can define stages in GitHub Actions workflow by adding the following commands to your GitHub Action workflow:\n\n```\nsteps:\n    - uses: actions/checkout@v2\n    - uses: hashicorp/setup-terraform@v1\n    with:\n        terraform_wrapper: false\n    - name: Terraform Init\n    id: init\n    run: |\n        rm -rf .terraform\n        terraform init\n    - name: Terraform Plan\n    id: plan\n    run: terraform plan\n    - name: Terraform Apply\n    if: github.ref == 'refs/heads/main'\n    id: apply\n    run: terraform apply -auto-approve\n    - name: Terraform destroy\n    if: github.ref == 'refs/heads/destroy'\n    id: destroy\n    run: terraform destroy -auto-approve\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevenes%2Fterraform-php-beanstalk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdevenes%2Fterraform-php-beanstalk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevenes%2Fterraform-php-beanstalk/lists"}