Deploying Laravel to Elastic Beanstalk with Runtime 2 (PHP 7.4)

If you recently tried to deploy a Laravel app to elastic beanstalk using nginx + PHP 7.4 then you must know that whenever you try to access any of your app routes it will throw an 404 error.

Image for post

Well, this happens because the latest elastic beanstalk runtime uses nginx as default web server in replacement of Apache, the one being use in the oldest versions.

A lot of users just decide to ditch php 7.4 and go back to php 7.2 with the older runtime and problem solved. Well you don’t need to.

How do I fix this?

All you have to do is create this file

.platform/nginx/conf.d/elasticbeanstalk/

And inside of it, paste your regular try_files directive.

location / {
    try_files $uri $uri/ /index.php?$query_string;
    gzip_static on;
}

Then commit / deploy it using your regular** eb deploy **or using a zip file. This will automatically make your routes work properly again.

And of course, you can add any other directives inside this file. Just be careful about what elastic beanstalk supports.

#elastic-beanstalk #aws #php #nginx #laravel

Deploying Laravel App to Elastic Beanstalk with Runtime 2
19.15 GEEK