Search code examples
phprestslimshared-hostingslim-3

SLIM Error :: AuthController not found when SLIM app hosted on server


I have a REST api app using SLIM framework. Below is my app dir structure enter image description here

Below is structure in my controllers dir

enter image description here

Authcontroller.php is in Auth folder.

Below are namespaces given to ActionController and Authcontroller enter image description here enter image description here

Both controllers (Action and Auth) are defined in container as below in the mainapp enter image description here

Above app is working fine on my localhost ,but when i upload same to my server, it get below error on above line 58 enter image description here

Please help me here , i am going mad,have changed around 3 hosting servers(SHARED-HOSTING),but still same error. PLEASE HELP!!


Solution

  • If your deployment server is Linux, mostly, because path is case-sensitive.

    If your composer.json contains section such as below

    ...
    "autoload": {
        "psr-4": {
            "App\\": "app"
        },
    },
    ...
    

    Composer PSR-4 autoloading expect to find class

    \App\Controllers\Auth\AuthController
    

    in file

     app\Controllers\Auth\AuthController.php
    

    but it can not find it because yours is

     app\controllers\Auth\AuthController.php
    

    Since your development machine seems to use Windows which by default is case-insensitive,

     app\controllers\Auth\AuthController.php
    

    equals to

     app\Controllers\Auth\AuthController.php
    

    Which is why it works on your development machine but not on deployment server.

    So the solution is to rename any directory/files to match its case and also make sure that all files is copied to deployment server.

    After you change directory/filename case, run

    $ composer dump-autoload

    So new autoload file is generated.