Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

404 on Laravel Elastic BeanStalk

I am trying to deploy a Laravel 7 application to Elastic BeanStalk but having some problem with the routing.

I have followed the tutorial from the video below and upload the zip archive with all my local files. I have also fixed the permission issue after having set the root to /public. Currently, the only page visible is the homepage whereas al the other pages like /login, /register and the other show me a 404

here is the log of the from eb:

2020/05/01 14:19:30 [error] 4091#0: *4 open() "/var/www/html/public/login" failed (2: No such file or directory), client: 82.4.194.3, server: , request: "GET /login HTTP/1.1"

https://www.youtube.com/watch?v=ISVaMijczKc

like image 313
Nico Anastasio Avatar asked May 01 '20 14:05

Nico Anastasio


2 Answers

I suppose you are using Beanstalk PHP platform with Linux in version 2; this version uses Nginx (whereas the previous version uses Apache).

You can see more details in the official documentation: https://docs.aws.amazon.com/elasticbeanstalk/latest/platforms/platforms-supported.html#platforms-supported.PHP

In that case, you have to configure Nginx for redirection as described in the Laravel documentation: https://laravel.com/docs/7.x/deployment#nginx

Just create the file .platform/nginx/conf.d/elasticbeanstalk/laravel.conf (at the root of your project):

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

Feel free to add other configuration for your need.

You will find more details about extending the platform here: https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/platforms-linux-extend.html

like image 196
Benjamin Avatar answered Nov 16 '22 22:11

Benjamin


After several attempts, I have it up and running. I had deleted the application and used EB CLI to create it again.

I created an environment config and placed it in .ebextentions and I added AllowOverride All

Here is the content of my 01-environment.config

option_settings:
 aws:elasticbeanstalk:container:php:phpini:
   document_root: /public
   composer_options: --no-dev
 aws:elasticbeanstalk:application:environment:
   APP_ENV: production
   APP_KEY: base64:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

and my .htaccess file

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews -Indexes
    </IfModule>

    RewriteEngine On

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]
    AllowOverride All
    # Send Requests To Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>
like image 2
Stacy Thompson Avatar answered Nov 16 '22 23:11

Stacy Thompson