{"id":15457528,"url":"https://github.com/rennokki/laravel-aws-eb","last_synced_at":"2025-04-04T13:09:08.528Z","repository":{"id":42224739,"uuid":"196688033","full_name":"rennokki/laravel-aws-eb","owner":"rennokki","description":"Ready-to-deploy configuration to run Laravel on AWS Elastic Beanstalk.","archived":false,"fork":false,"pushed_at":"2024-05-15T11:21:28.000Z","size":159,"stargazers_count":488,"open_issues_count":18,"forks_count":130,"subscribers_count":25,"default_branch":"master","last_synced_at":"2025-03-28T12:03:30.746Z","etag":null,"topics":["amazon","amazon-linux-ami","ami","aws","aws-eb","beanstalk","ebextensions","ec2","elastic","elastic-beanstalk","laravel","spot-instances"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rennokki.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-07-13T06:41:16.000Z","updated_at":"2025-03-26T09:50:08.000Z","dependencies_parsed_at":"2024-10-22T22:55:28.461Z","dependency_job_id":null,"html_url":"https://github.com/rennokki/laravel-aws-eb","commit_stats":{"total_commits":101,"total_committers":8,"mean_commits":12.625,"dds":0.3465346534653465,"last_synced_commit":"4d28a4516ee290e636ac6586f65dd9978237429a"},"previous_names":[],"tags_count":31,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rennokki%2Flaravel-aws-eb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rennokki%2Flaravel-aws-eb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rennokki%2Flaravel-aws-eb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rennokki%2Flaravel-aws-eb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rennokki","download_url":"https://codeload.github.com/rennokki/laravel-aws-eb/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247175695,"owners_count":20896337,"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":["amazon","amazon-linux-ami","ami","aws","aws-eb","beanstalk","ebextensions","ec2","elastic","elastic-beanstalk","laravel","spot-instances"],"created_at":"2024-10-01T22:46:35.569Z","updated_at":"2025-04-04T13:09:08.501Z","avatar_url":"https://github.com/rennokki.png","language":"Shell","funding_links":["https://www.patreon.com/bePatron?u=10965171"],"categories":[],"sub_categories":[],"readme":"# Laravel Elastic Beanstalk\n\nLaravel EB is a sample configuration to help you deploy a Laravel app on an AWS Elastic Beanstalk PHP environment without any super rockety-like knowledge.\n\n## 🤝 Supporting\n\nIf you are using one or more Renoki Co. open-source packages in your production apps, in presentation demos, hobby projects, school projects or so, spread some kind words about our work or sponsor our work via Patreon. 📦\n\nYou will sometimes get exclusive content on tips about Laravel, AWS or Kubernetes on Patreon and some early-access to projects or packages.\n\n[\u003cimg src=\"https://c5.patreon.com/external/logo/become_a_patron_button.png\" height=\"41\" width=\"175\" /\u003e](https://www.patreon.com/bePatron?u=10965171)\n\n# Amazon Linux 2\n\nThis branch is working with the new Amazon Linux 2.\n\nIt's highly recommended to upgrade to the Amazon Linux 2 version, since it's faster and more secure. ([see AWS's announcement](https://aws.amazon.com/about-aws/whats-new/2020/04/aws-elastic-beanstalk-announces-general-availability-of-amazon-linux-2-based-docker-corretto-and-python-platforms/))\n\nTo upgrade to AL2 from your Amazon Linux AMI, please see the [Amazon Linux 2 migration guide](https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/using-features.migration-al.html)\n\nIf you still work with Amazon Linux AMI, please switch to the [amazon-ami branch](../../tree/amazon-ami) to read the older docs.\n\n# Packaged\n\nThe sample configuration comes with:\n\n- Automation for copying .env file from AWS EB's S3 bucket (so you won't have to add the env variables from the AWS Console)\n- Laravel Artisan Scheduler CRON configuration\n- Supervisor for Queues\n- HTTP to HTTPS support\n- Nginx configuration support\n- Chromium binary\n\n# Updating\n\nThe repo works with semantic versioning, so please check the [Releases](../../releases) page for latest updates \u0026 changes.\n\n# Installation\n\nClone the repo and drop the `.ebextensions` and `.platform` folders in your root project.\n\nMake sure that the .sh files from the `.platform` folder are executable before deploying your project:\n\n```bash\n$ chmod +x .platform/hooks/prebuild/*.sh\n```\n\n```bash\n$ chmod +x .platform/hooks/predeploy/*.sh\n```\n\n```bash\n$ chmod +x .platform/hooks/postdeploy/*.sh\n```\n\n```bash\n$ chmod +x .platform/scripts/*.sh\n```\n\n# AWS EB Should-Know\n\n## Deployment Stages\n\nElastic Beanstalk helps you deploy apps while keeping them up, so you won't have to turn your app down during deployments. For this, there are two paths:\n\n- `/var/app/staging` that holds the app between deployments. This folder is not pointed to until the deployment finishes\n- `/var/app/current` that holds the live app and that serves requests actively\n\nEach deploy makes you lose everything you have in the `current` folder. **DO NOT** rely on local storage, use S3 instead with CloudFront to avoid data loss and speed up the things.\n\n## .ebextensions/\n\nThe `.ebextensions` folder contains information about which commands to run during the deployment, such as migrations or copying files in the instance.\n\nIn this repo, see `01_deploy.config` for a list of commands that will be ran upon deployment.\n\nOn the other hand, the `00_copy_env_file.config` will copy the `.env` file from your S3 bucket and put it temporarily in the `/tmp` folder, to later be copied in the deployment process.\n\nPlease open the files to see further comments on the particular sections and change them.\n\n## .platform/\n\nThe `.platform` folder contains mostly shell scripts that will be ran during the deployment, like configuring or installing software, like supervisor, or running scripts after the deployment finished.\n\nConsider looking in the `files/` folder for Supervisor and PHP custom configurations that will be automatically be applied, out-of-the-box.\n\nAdditionally, the `hooks/`folder contains scripts that will be ran during various deployment stages. All scripts contain comments about details and best practices, so take a look.\n\nPlease refer to this scheme to understand the execution workflow: https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/images/platforms-linux-extend-order.png\n\n# Use Cases\n\n## HTTP to HTTPS\n\nCheck the `.platform/nginx/conf.d/elasticbeanstalk/https.conf` file to enable HTTP to HTTPS redirect.\n\n## Laravel Passport\n\nSince Laravel Passport uses local storage to keep the public and private key, there is no way of using this method. Instead, you might use what this PR added: https://github.com/laravel/passport/pull/683\n\nIn your `.env` file, add the following variables **and make sure that there is a `\\\\n` for each newline**:\n\n```\nPASSPORT_PRIVATE_KEY=\"-----BEGIN RSA PRIVATE KEY-----\\\\nMIIJJwIBAAKCAgEAw3KPag...\\\\n-----END RSA PRIVATE KEY-----\"\nPASSPORT_PUBLIC_KEY=\"-----BEGIN PUBLIC KEY-----\\\\nMIICIjANBgkqhkiG9w0BAQEFAAOC...\\\\n-----END PUBLIC KEY-----\\\\n\"\n```\n\n## Spatie Media Library \u0026 other Imagick-based packages\n\nSome packages require Imagick to run.\n\nTo enable Imagick installation on the instance via Amazon Linux Extras, check `install_imagick.sh` file for details.\n\n## Memcached Auto Discovery\n\nMemcached Auto Discovery for AWS Memcached is a PHP extension that replace the default Memcached extension, in order to use Memcached clusters in multi-node mode.\n\nPlese see `install_memcached_discovery.sh` file to enable the installation for your PHP version.\n\nFor the Laravel app, edit your `memcached` connection in `cache.php` to make it suitable for multi-node configuration:\n\n```php\n'memcached' =\u003e [\n    'driver' =\u003e 'memcached',\n    \n    'persistent_id' =\u003e env('MEMCACHED_PERSISTENT_ID', 1), // make sure you also set a default to the persistent_id\n    \n    'options' =\u003e array_merge([\n        Memcached::OPT_DISTRIBUTION =\u003e Memcached::DISTRIBUTION_CONSISTENT,\n        Memcached::OPT_LIBKETAMA_COMPATIBLE =\u003e true,\n        Memcached::OPT_SERIALIZER =\u003e Memcached::SERIALIZER_PHP,\n    ], in_array(env('APP_ENV'), ['production', 'staging']) ? [\n        Memcached::OPT_CLIENT_MODE =\u003e Memcached::DYNAMIC_CLIENT_MODE,\n    ] : []),\n]\n```\n\n**For production \u0026 staging workloads (when AWS Elasticache is used), `Memcached::OPT_CLIENT_MODE` should be set. `OPT_CLIENT_MODE` and `DYNAMIC_CLIENT_MODE` are Memcached Auto Discovery extension-related constants, not available in the default Memcached extension.**\n\n## Chromium binary support\n\nSome Laravel apps, like crawlers, might need a Chrome binary to run upon. A good example is [spatie/browsershot](https://github.com/spatie/browsershot#custom-chromechromium-executable-path). It lets you take browser screenshots using PHP and a Chromium binary.\n\nTo install Chromium, seek for the `install_latest_chromium_binary.sh` script and uncomment the code.\n\nThe binary can be then accessed from `/usr/bin/google-chrome-stable`\n\n## Run on Spot Instances\n\nSpot instances are the cheapest EC2 instances from AWS, but they can be terminated\nanytime. Please refer to this to understand how they can be used: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-spot-instances.html\n\nSpot instances can be configured from the console. Check out AWS announcement: https://aws.amazon.com/about-aws/whats-new/2019/11/aws-elastic-beanstalk-adds-support-for-amazon-ec2-spot-instances/\n\n# Multi-environment\n\nSometimes you might have more than one environment, for example production and staging. Having duplicate configuration can be tricky, but you can workaround this problem by seeking a CloudFromation-like appoach as presented in one of the issues: https://github.com/rennokki/laravel-aws-eb/issues/30#issuecomment-693154271\n\nThe idea behind it is to use, for example, `{\"Ref\": \"AWSEBEnvironmentName\"}` value to concatenate to the name of the .env file that should be downloaded from S3. This way, you can have `.env.staging-app` if your AWS EB environment is named `staging-app`.\n\n# Deploying from the CI/CD Pipeline\n\nTo deploy to the EB environment, you have two choices:\n\n- Archive the ZIP by your own and upload it.\n- Pull from git, and use AWS EB CLI in the current folder (with no additional ZIP-ing)\n\nAWS EB CLI make use of `.gitignore` and `.ebignore`. The only pre-configuration you need is to add the following environment variables\nto your CI/CD machine:\n\n- `AWS_ACCESS_KEY_ID`\n- `AWS_SECRET_ACCESS_KEY`\n- `AWS_EB_REGION`\n\nIf you use a dockerized CI/CD pipeline (like Gitlab CI), you can make use of the `renokico/aws-cli:latest` image.\n\nThe following commands let you deploy an app on a certain environment within Gitlab CI on tag creation, for example:\n\n```bash\n$ git checkout $CI_COMMIT_TAG\n```\n\n```bash\n$ eb init --region=$AWS_EB_REGION --platform=php [project-name]\n```\n\n```bash\n$ eb use [environment-name]\n```\n\n```bash\n$ eb deploy [environment-name] --label=$CI_COMMIT_TAG\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frennokki%2Flaravel-aws-eb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frennokki%2Flaravel-aws-eb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frennokki%2Flaravel-aws-eb/lists"}