skip to Main Content

I recently started using AWS, and I am trying to deploy my Symfony API to Elastic Beanstalk. I follow the steps in the tutorial but in the end I get the same result over and over:

Default route "/" returns the expected result, however all other endpoints return a 404 nginx error. I have seen similar questions been asked in other posts (see this Laravel one) but since I have never worked with nginx I do not know how to fix my issue based on those.

Any help is appreciated!

2

Answers


  1. The production version of Symfony needs a web pack — I use Apache, see the docs

    https://symfony.com/doc/current/setup/web_server_configuration.html

    Basically just change the Elastic Beanstalk configuration to use Apache instead of Nginx and run this on your application code

    composer require symfony/apache-pack
    

    Then commit and eb deploy and you’ll be in business.

    Login or Signup to reply.
  2. The AWS tutorial provides a rudimentary nginx configuration file that does not provide a location definition needed by a symfony app when using api-platform. The solution is to provide your own nginx config file that provides for the proper locations

    #/etc/nginx/conf.d/elasticbeanstalk/php.conf
    
    
    location / {
        # try to serve file directly, fallback to index.php
        try_files $uri /index.php$is_args$args;
    }
    
    
    location ~* .(?:ico|css|js|gif|webp|jpe?g|png|svg|woff|woff2|eot|ttf|mp4)$ {
        # try to serve file directly, fallback to index.php
        try_files $uri /index.php$is_args$args;
        access_log off;
        expires 1y;
        add_header Pragma public;
        add_header Cache-Control "public";
    }
    
    location ~ ^/index.php(/|$) {
        include /etc/nginx/fastcgi_params;
        fastcgi_pass php-fpm;
        fastcgi_split_path_info ^(.+.php)(/.*)$;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        fastcgi_param DOCUMENT_ROOT $realpath_root;
    
        internal;
    }
    

    AWS elastic beanstalk provides a mechanism to update this file using the .platform folder in your develop directory.

    Checkout this excellent github example by Alexander Schranz of the elastic beanstalk for a symfony app. It provides for the proper nginx configuration and also several useful deployment scripts needed by most symfony apps.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search