skip to Main Content

I have build a custom MVC Framework.
Local its working fine, when I try to get it working on a live shared hosting server I will get this error:

Error Message in Browser:

Fatal error: Uncaught Error: Class ‘AppConfig’ not found in /www/htdocs/user/project/public/index.php:19 Stack trace: #0 {main} thrown in /www/htdocs/user/project/public/index.php on line 19

Composer.json file:

{
  "require": {
    "filp/whoops": "^2.3",
    "phpmailer/phpmailer": "^6.0"
  },
  "autoload": {
    "psr-4": {
      "Core\": "core/",
      "App\": "app/"
    }
  }
}

My Folder & File structure: (The whole project is inside the folder: “project”)

enter image description here

Index.php File

    <?php

/**
 * Front controller
 */

use AppConfig;

/**
 * Composer autoloading
 */

require dirname(__DIR__) . '/vendor/autoload.php';

/**
 * Whoops Error and Exception handling
 */

if (Config::SHOW_ERRORS == true){
    $whoops = new WhoopsRun;
    $whoops->pushHandler(new WhoopsHandlerPrettyPageHandler);
    $whoops->register();
}

/**
 * Sessions
 */

session_start();

/**
 * Routing
 */

$router = new CoreRouter();

// Add the routes
$router->add('', ['controller' => 'Home', 'action' => 'index']);

Config.php file:

<?php

/**
 * Application configuration
 */

namespace App;

class Config {

    /**
     * Database host
     * @var string
     */

    const DB_HOST = 'localhost';

    /**
     * Mail SMTP Port
     * @var int
     */

    const SMTP_PORT = '2525';
}

My method to deploy to the server:

  1. ZIP the local files & Export mysql database
  2. upload zip to server -> unzip it
  3. upload db to phpmyadmin
  4. Change database credentials in Config File
  5. run composer install (I also tried: composer install --no-dev)
  6. Done

I have repeated this procedure for several times now but its still not working

3

Answers


  1. I have just tried to do the same thing and it seems work, check this:

    /index.php

    <?php
    
    require dirname(__DIR__) . '/vendor/autoload.php'; // It must be called first
    
    use AppConfig;
    
    echo Config::get('test');
    // Result: test
    

    /App/Config.php

    namespace App;
    
    class Config 
    {
        public function get($str)
        {   
            return $str;
        }
    }
    

    Login or Signup to reply.
  2. This is case sensitivity problem – your autoloading rules uses app as directory name, but this is actually App. This may work on case insensitive filesystems (Windows) but it will not work on case sensitive filesystems (Linux). You should fix your autoloading rules to:

    {
      "require": {
        "filp/whoops": "^2.3",
        "phpmailer/phpmailer": "^6.0"
      },
      "autoload": {
        "psr-4": {
          "Core\": "Core/",
          "App\": "App/"
        }
      }
    }
    
    Login or Signup to reply.
  3. In my case, the problem was caused by using a Symbolic Link in Windows.
    I am using WAMP and PHP framework CodeIgniter (version 4.2.1). Some versions of CodeIgniter have issues with this.

    Possible cause:

    I think the cause is the use of the PHP function file_exists. The function returns a FALSE in some cases when the path contains a symbolic link with certain characters.
    Or the problem is in sanitizing the filename.

    Possible solutions:

    1. Ask the developers of CodeIgniter to fix this problem. I can’t wait for that now.
    2. Override the functions of the framework in which the problem occurs. Takes me too much time to figure this out.
    3. Use an older version of CodeIgniter that does not have the issue. This, of course, has other drawbacks.
    4. Do not use a symbolic link. Duh!
    5. Make sure the symbolic link does not contain any ‘special’ characters.

    Solution 5 was the easiest for me. I had to remove the brackets () in my symbolic link name and that solved the problem.

    Maybe this helps someone else.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search