Got Error while using slim framework on web server

Hi all,
I develop a small api using slim framework and it worked successfully in local server.
and then I upload all the files on web server. It did not worked. Used web server [ Apache and PHP in ubuntu ]

For example:

   $app->get('/', function (Request $request, Response $response) 
   {
       $response->getBody()->write('Hello world!');
       return $response;
   });

This code worked successfully. When I enter 185.546.23.54/Folder_Name/public This will give correct output (Hello world!) [185.546.23.54 Just for example]

But, The below code got error.

  $app->group('/users', function (Group $group) 
    {
        $group->get('', ListUsersAction::class);
        $group->get('/{id}', ViewUserAction::class);
    });

When I enter 185.546.23.54/Folder_Name/public/users it will give the below error.

Error I got: [185.546.23.54/Folder_Name/public/users]

# Not Found

The requested URL was not found on this server.

Apache/2.4.41 (Ubuntu) Server at 185.546.23.54 Port 80

And Sometimes 185.546.23.54/Folder_Name/public this URL give correct output, sometime give error output.

Error I got : [185.546.23.54/Folder_Name/public]

{
    "statusCode": 500,
    "error": {
        "type": "SERVER_ERROR",
        "description": "ERROR: Module 'pgsql' already loaded on line 0 in file Unknown."
    }
}

Any configuration Needed ? Any suggestion ?

Thanks

Hi @prkvv

To make it work, you must enable Apache mod_rewrite and the DocumentRoot must point to the public/ directory of your application.

Read more: Apache configuration

When you run your application in a sub-directory of the DocumentRoot, you also have to set the basePath of the Slim $app instance.

1 Like

Hi @odan
Thanks for your response.

I did all the apache configuration. Still got error.

Error I got : When I enter 185.546.23.54/Folder_Name/public/users

{
    "statusCode": 500,
    "error": {
        "type": "SERVER_ERROR",
        "description": "The stream or file \"\/var\/www\/html\/Folder_Name\/app\/..\/logs\/app.log\" could not be opened in append mode: failed to open stream: Permission denied"
    }
}

Any suggestion?

Thanks

Solved. I gave it chmod -R 777 /app.log it worked.

Ok, great.

Please note that the public/ directory must not be part of the URL.

2 Likes