0

Using symfony 6.2 with api-platform/core and successfully created several dynamic routes based on #[ApiResources] annotations on Entity classes. The localhost environment (mac) http://localhost:8001/api/docs successfully displays the docs and all the endpoints work; However, when deployed to an AWS instance the /api routes all get a 404 error. When I set the document root to /public I do successfully get the default symfony web page.

The AWS deployment:

  • Platform & Solution Stack Name: PHP 8.1 AL2 version 3.5.2 (64bit Amazon Linux 2 v3.5.2 running PHP 8.1)

  • Language: PHP 8.1.13

  • Composer: 2.3.5

  • Proxy Server: nginx 1.22.0

The config/packages and config/routes where not altered from the initial composer generated install

app/config/routes/api_plaform.yaml

api_platform:
    resource: .
    type: api_platform
    prefix: /api

app/config/routes.yaml

controllers:
    resource:
        path: ../src/Controller/
        namespace: App\Controller
    type: attribute

Each Entity.php class has this kind of #[ApiResource] Annotation:

#[ORM\Entity(repositoryClass: ProjectRepository::class)]
#[ORM\EntityListeners(['App\EventListener\ProjectChangedNotifier'])]
#[ApiResource(
    normalizationContext: ['groups' => ['read']],
    denormalizationContext: ['groups' => ['write']]
)]
class Project
{
    #[ORM\Id]
    #[ORM\GeneratedValue]
    #[ORM\Column]
    private ?int $id = null;
...

Any ideas on how to debug the routes on the AWS instance?

1
  • can you provide more information about what kind of instance are you using? also the type of stack in the AWS instance? also the apache/nginx configuration, version of php installed in your local machine vs aws intance Commented Dec 17, 2022 at 7:01

1 Answer 1

0

The solution to my issue is realizing the AWS default elastic beanstalk php.conf does not provide a location definition needed by a symfony app when using api-platform. I solved the issue by providing my own nginx config file that does 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 .ebextentions and .platform for a symfony app. It provides for the proper nginx configuration and also several useful deployment scripts needed by most symfony apps.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.