# Server Error: 500, class Database not found

**URL:** <https://discourse.slimframework.com/t/server-error-500-class-database-not-found/4480>\
**Category:** Questions\
**Created:** [November 1, 2020, 10:55pm UTC](https://discourse.slimframework.com/t/server-error-500-class-database-not-found/4480 "2020-11-01T22:55:07Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dgreat](https://avatars.discourse-cdn.com/v4/letter/d/ce73a5/32.png) [@dgreat](https://discourse.slimframework.com/u/dgreat)\
**Post date:** [November 1, 2020, 10:55pm UTC](https://discourse.slimframework.com/t/server-error-500-class-database-not-found/4480/1 "2020-11-01T22:55:07Z")

</div>

Hello everyone,  
I am using php slim for the first time to build APIs but I encountered an error after hosting it on a shared server. Whenever I make an API call through postman I get the error message below, though my Database class is configured correctly and uploaded to the server as well (location: public\_html/api/src/Model/). Please help me  
{  
“statusCode”: 500,  
“error”: {  
“type”: “SERVER\_ERROR”,  
“description”: “Class ‘App\Db\Database’ not found”  
}  
}  
Here is my controller:  
namespace App\Controllers;

```
use App\Db\Database;
use Firebase\JWT\JWT;
use Respect\Validation\Exceptions\NestedValidationException;
use Slim\Psr7\Response;
use Respect\Validation\Validator as v;

class LoginController
{
       public function __construct($data, Response $response)
      {
$validator = v::keySet(
    v::key('username', v::stringType()->notEmpty()->setName('username')->length(2, 100)),
    v::key('password', v::stringType()->notEmpty()->setName('password'))
);

try {
    $validator->assert($data);
} catch (NestedValidationException $e) {
    $response->getBody()->write(json_encode([
        'responseCode' => "13",
        'responseMessage' => $e->getMessages(),
    ]));
    return $response->withHeader('Content-Type', 'application/json');
}

$username = $data['username'];
$password = $data['password'];

$hash_pwd = password_hash($password, PASSWORD_DEFAULT);
$db = Database::getInstance();

$login_query =
    $db->select(
        'users',
        [
            'email_address',
            'passwords'
        ],
        [
            'email_address' => $username,
        ]
    );

if (!$login_query) {
    $response->getBody()->write(json_encode([
        'responseCode' => '99',
        'responseMessage' => "Invalid Login Details"
    ]));
} else {
    $user_hash_pwd = $login_query[0]['passwords'];
    $password_verify = password_verify($password, $user_hash_pwd);
    if ($password_verify) {
        $key = "!@#$%^&*()_+";
        $payload = array(
            "iss" => "http://localhost",
            "aud" => "http://localhost",
            'iat' => time(),
            'uid' => 1,
            'exp' => time() + 10,
        );
        $token = JWT::encode($payload, $key);
        $decoded = JWT::decode($token, $key, array('HS256'));

        $response->getBody()->write(json_encode([
            'responseCode' => '0',
            'responseMessage' => "Logged In",
            'responseBody' => [
                'token' => $token
            ]
        ]));
    } else {
        $response->getBody()->write(json_encode([
            'responseCode' => '99',
            'responseMessage' => "Incorrect password"
        ]));
    }
}

```

}  
}

---

<div class="post-metadata">

**Author:** ![odan](https://avatars.discourse-cdn.com/v4/letter/o/9de053/32.png) [@odan](https://discourse.slimframework.com/u/odan)\
**Post date:** [November 3, 2020, 11:38am UTC](https://discourse.slimframework.com/t/server-error-500-class-database-not-found/4480/2 "2020-11-03T11:38:57Z")

</div>

This is just an autoloading configuration issue. Please show us your composer.json “autoload” section.

For example:

```auto
"autoload": {
    "psr-4": {
        "App\\": "src/"
    },

```

---

<div class="post-metadata">

**Author:** ![dgreat](https://avatars.discourse-cdn.com/v4/letter/d/ce73a5/32.png) [@dgreat](https://discourse.slimframework.com/u/dgreat)\
**Post date:** [November 3, 2020, 12:50pm UTC](https://discourse.slimframework.com/t/server-error-500-class-database-not-found/4480/3 "2020-11-03T12:50:52Z")

</div>

> [@odan](#):
>
> section

```
"autoload": {
"psr-4": {
  "App\\": "src/",
  "App\\Db\\": "src/Model/"
   }
  }

```

---

<div class="post-metadata">

**Author:** ![odan](https://avatars.discourse-cdn.com/v4/letter/o/9de053/32.png) [@odan](https://discourse.slimframework.com/u/odan)\
**Post date:** [November 4, 2020, 1:04pm UTC](https://discourse.slimframework.com/t/server-error-500-class-database-not-found/4480/4 "2020-11-04T13:04:46Z")

</div>

> [@dgreat](#):
>
> `"App\\Db\\": "src/Model/"`

The second entry could cause the issue in combination with another namespace. I would try to follow PSR-4 as it is intended. Try to remove the second entry `"App\\Db\\": "src/Model/"`, move the file `src/Model/Database.php` to `src/Db/Database.php` and run `composer dump-autoload` or `composer update`.

---

<div class="post-metadata">

**Author:** ![dgreat](https://avatars.discourse-cdn.com/v4/letter/d/ce73a5/32.png) [@dgreat](https://discourse.slimframework.com/u/dgreat)\
**Post date:** [November 4, 2020, 2:33pm UTC](https://discourse.slimframework.com/t/server-error-500-class-database-not-found/4480/5 "2020-11-04T14:33:22Z")

</div>

I have been able to solve the problem. I changed the database.php file to Database.php and it worked. Thanks for your responses I really appreciate. Slim is really fun and easy.
