How to deploy on shared server production?

Hi, I just deployed my Slim 4 (Skeleton) on my production server, that is a shared server.

The slim project is inside an API folder.

And I changed the htaccess from api/ folder to:

<IfModule mod_rewrite.c>
   RewriteEngine on
      
   RewriteRule ^$ public/     [L]
   RewriteRule (.*$) public/$1 [L]
</IfModule>

And the htaccess from api/public to:

<IfModule mod_rewrite.c>
  RewriteEngine On

  RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
  RewriteRule ^(.*) - [E=BASE:%1]
  
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^ index.php [QSA,L]
</IfModule>

But it always returning the 404 response for all routes.

{
    "statusCode": 404,
    "error": {
        "type": "RESOURCE_NOT_FOUND",
        "description": "Not found."
    }
}

However if I run locally using composer start, everything works very well.

Does anybody has any clue on how to solve that?

Thanks,

Ricardo Bonino

Hi @Bonino Have you tried to set the correct base path?
For example: $app->setBasePath('/api');

@odan Thank you very much. That works. This is my first slim app and enjoying so much

1 Like

Hello everyone,

I have a similar issue. Mine returns 500:
{
ā€œstatusCodeā€: 500,
ā€œerrorā€: {
ā€œtypeā€: ā€œSERVER_ERRORā€,
ā€œdescriptionā€: ā€œClass ā€˜App\Db\Databaseā€™ not foundā€
}
}

Though the Database Class exist in src/Model folder.
Please helpā€¦

I read your question and fixed my issues when I deploy api to shared hosting.

Thanks for 2 row of code:

RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.)::\2$
RewriteRule ^(.
) - [E=BASE:%1]