Nathan Lima
Nathan Lima

Reputation: 503

Getting 404 after deploying Laravel 8 on AWS Elastic Beanstalk

I'm trying to set up an staging environment (I also intend to set up a production futhermore) for a Laravel 8 application. almost everithing is working as I expected, except for a problem caching the routes and with something wrong on nginx configuration. I created a laravel.conf file on .platfom/nginx/conf.d/elasticbeanstalk folder with the following content:

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

but it seem to take no effect.

Here are the configuration files that I'm using:

01-setup.config:

commands:
  01updateComposer:
    command: export COMPOSER_HOME=/root && /usr/bin/composer.phar self-update
option_settings:
  - namespace: 'aws:elasticbeanstalk:application:environment'
    option_name: COMPOSER_HOME
    value: /root
  - namespace: 'aws:elasticbeanstalk:container:php:phpini'
    option_name: document_root
    value: /public
  - namespace: 'aws:elasticbeanstalk:container:php:phpini'
    option_name: composer_options
    value: '--no-dev --no-interaction --prefer-dist --optimize-autoloader'
container_commands:
  01-install_composer_dependencies:
    command: >-
      sudo php -d memory_limit=-1 /usr/bin/composer.phar install --no-dev
      --no-interaction --prefer-dist --optimize-autoloader
    cwd: /var/app/staging
  02-optimize:
    command: /usr/bin/composer.phar dump-autoload --optimize


03-artisan.config

container_commands:
  01_migrate:
    command: php artisan migrate --force
    cwd: /var/app/staging/
    leader_only: true
  02_seed:
    command: php artisan db:seed --force
    cwd: /var/app/staging/
    leader_only: true
  03_clear_route:
    command: sudo php artisan route:clear
    cwd: /var/app/staging/
  04_clear_cache:
    command: sudo php artisan cache:clear
    cwd: /var/app/staging/
  05_clear_optimize:
    command: sudo php artisan optimize:clear
    cwd: /var/app/staging/
  06_optimize:
    command: sudo php artisan optimize
    cwd: /var/app/staging/
  07_clear_config:
    command: sudo php artisan config:clear
    cwd: /var/app/staging/
  08_link_storage_folder:
    command: sudo php artisan storage:link
    cwd: /var/app/staging/

04-change-permissions.config

container_commands:
  01_storage_permissions:
    command: chmod 777 -R /var/app/staging/storage
    cwd: /var/app/staging/
  02_cache_permissions:
    command: chmod 777 -R /var/app/staging/bootstrap/cache/
    cwd: /var/app/staging/

I also tried to override the default nginx.conf but I didn't succeeded.

Some environmets detalis:

EB platform: PHP 7.4 running on 64bit Amazon Linux 2

NGINX: 1.18.0

Upvotes: 1

Views: 823

Answers (1)

Chris Cynarski
Chris Cynarski

Reputation: 513

In the UI (Configuration -> Software section) you should set the Document Root setting to /public.

See AWS tutorial for more information

Upvotes: 2

Related Questions