Laravel 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.
If 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.
You will sometimes get exclusive content on tips about Laravel, AWS or Kubernetes on Patreon and some early-access to projects or packages.
This branch is working with the new Amazon Linux 2.
It's highly recommended to upgrade to the Amazon Linux 2 version, since it's faster and more secure. (see AWS's announcement)
To upgrade to AL2 from your Amazon Linux AMI, please see the Amazon Linux 2 migration guide
If you still work with Amazon Linux AMI, please switch to the amazon-ami branch to read the older docs.
The sample configuration comes with:
The repo works with semantic versioning, so please check the Releases page for latest updates & changes.
Clone the repo and drop the .ebextensions
and .platform
folders in your root project.
Make sure that the .sh files from the .platform
folder are executable before deploying your project:
$ chmod +x .platform/hooks/prebuild/*.sh
$ chmod +x .platform/hooks/predeploy/*.sh
$ chmod +x .platform/hooks/postdeploy/*.sh
$ chmod +x .platform/scripts/*.sh
Elastic 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:
/var/app/staging
that holds the app between deployments. This folder is not pointed to until the deployment finishes/var/app/current
that holds the live app and that serves requests activelyEach 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.
The .ebextensions
folder contains information about which commands to run during the deployment, such as migrations or copying files in the instance.
In this repo, see 01_deploy.config
for a list of commands that will be ran upon deployment.
On 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.
Please open the files to see further comments on the particular sections and change them.
The .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.
Consider looking in the files/
folder for Supervisor and PHP custom configurations that will be automatically be applied, out-of-the-box.
Additionally, 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.
Please refer to this scheme to understand the execution workflow: https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/images/platforms-linux-extend-order.png
Check the .platform/nginx/conf.d/elasticbeanstalk/https.conf
file to enable HTTP to HTTPS redirect.
Since 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
In your .env
file, add the following variables and make sure that there is a \\n
for each newline:
PASSPORT_PRIVATE_KEY="-----BEGIN RSA PRIVATE KEY-----\\nMIIJJwIBAAKCAgEAw3KPag...\\n-----END RSA PRIVATE KEY-----"
PASSPORT_PUBLIC_KEY="-----BEGIN PUBLIC KEY-----\\nMIICIjANBgkqhkiG9w0BAQEFAAOC...\\n-----END PUBLIC KEY-----\\n"
Some packages require Imagick to run.
To enable Imagick installation on the instance via Amazon Linux Extras, check install_imagick.sh
file for details.
Memcached 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.
Plese see install_memcached_discovery.sh
file to enable the installation for your PHP version.
For the Laravel app, edit your memcached
connection in cache.php
to make it suitable for multi-node configuration:
'memcached' => [
'driver' => 'memcached',
'persistent_id' => env('MEMCACHED_PERSISTENT_ID', 1), // make sure you also set a default to the persistent_id
'options' => array_merge([
Memcached::OPT_DISTRIBUTION => Memcached::DISTRIBUTION_CONSISTENT,
Memcached::OPT_LIBKETAMA_COMPATIBLE => true,
Memcached::OPT_SERIALIZER => Memcached::SERIALIZER_PHP,
], in_array(env('APP_ENV'), ['production', 'staging']) ? [
Memcached::OPT_CLIENT_MODE => Memcached::DYNAMIC_CLIENT_MODE,
] : []),
]
For production & 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.
Some Laravel apps, like crawlers, might need a Chrome binary to run upon. A good example is spatie/browsershot. It lets you take browser screenshots using PHP and a Chromium binary.
To install Chromium, seek for the install_latest_chromium_binary.sh
script and uncomment the code.
The binary can be then accessed from /usr/bin/google-chrome-stable
Spot instances are the cheapest EC2 instances from AWS, but they can be terminatedanytime. Please refer to this to understand how they can be used: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-spot-instances.html
Spot 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/
Sometimes 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
The 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
.
To deploy to the EB environment, you have two choices:
AWS EB CLI make use of .gitignore
and .ebignore
. The only pre-configuration you need is to add the following environment variablesto your CI/CD machine:
AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY
AWS_EB_REGION
If you use a dockerized CI/CD pipeline (like Gitlab CI), you can make use of the renokico/aws-cli:latest
image.
The following commands let you deploy an app on a certain environment within Gitlab CI on tag creation, for example:
$ git checkout $CI_COMMIT_TAG
$ eb init --region=$AWS_EB_REGION --platform=php [project-name]
$ eb use [environment-name]
$ eb deploy [environment-name] --label=$CI_COMMIT_TAG
简短版本:如果使用类似AWS eb cli的方式进行上传,请验证是否已部署bootstrap / cache文件夹(而不是谈论其内容)。 我的答案背后有一些背景 我正在使用Amazon Web Services的Elastic Beanstalk托管我的Laravel项目。 当我刚开始使用Laravel时,我对其功能并不了解。 两天前我的新部署全部中途因OP的错误消息而崩溃。 那天早些时候,我意识
亚马逊aws 防止 关联 As promised, here is the 3rd free ExamPro AWS Certification course. This course prepares you to earn the coveted AWS Developer Associate Certification. 如所承诺的,这是第3个免费的ExamPro AWS认证课程。 本课程为
我在AWS Elasticache上有一个Redis 6. x实例。它是集群的,并且具有传输中加密。我还设置了RBAC(在AWS中使用密码的用户)。我能够使用进行连接,然后使用
我正在学习laravel,我已经在ec2实例上安装了所有东西。问题是当我运行php artisan service时,弹出的预览显示了这个图像: 来自aws c9预览的错误消息(无法加载http预览) 我试过这样运行它: php artisan serve——主机0.0。0.0—端口8080 但是,即使我使用我的公共IP地址在新页面中打开预览,我也会得到一个“无法访问此站点,xx.xx.xx.xx
我使用的是Laravel5.2,有一个多服务器自动伸缩的体系结构。我想在一个集中的位置有会话和缓存。我想用AWS弹力痛同样。 移动13841 some_ip_address_of_aws:6379 我尝试使用本地redis,它工作,所以predis工作正常。我试图在线查看解决方案,但无法获得解决方案。我认为配置endpoint正试图将redis连接重定向到我拥有的9个节点中的一个可用节点url。然
我有一个centos EC2和Laravel应用程序。我还在同一个EC2实例上安装了MySQL。它工作得很好。 现在我决定将MYSQL迁移到AWS RDS(MYSQL Aurora)。我可以通过Heidi连接到AWS RDS并进行查询,没有问题。 然而,在Laravel中,它抛出异常。我更改了DB_HOST、DB_DATABASE、DB_USERNAMEDB_PASSWORD的. env文件凭据。
基于此,我在我的应用程序中添加了相同的中间件,结果是重定向循环。 如果用户未通过身份验证,应用程序将重定向到登录页面,因此对我来说,这就是问题所在。也许不是。 ssl证书已正确安装且有效(如果我手动转到https://myapp.org 它按预期工作)。 主要的问题是,我使用整个应用程序的助手url()生成网址,现在我需要重定向到安全的网址。 我尝试删除该中间件,并将重定向添加到.htaccess
我想知道使用AWS OpsWorks与AWS Beanstalk和AWS CloudFormation的优缺点是什么? 我感兴趣的是一个可以自动伸缩的系统,它可以处理任意数量的并发web请求(从每分钟1000个请求到1000万rpm),包括一个可以自动伸缩的数据库层。 理想情况下,我希望有效地共享一些硬件资源,而不是为每个应用程序提供单独的实例。在过去,我主要使用EC2实例RDS Cloudtop