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”)
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:
- ZIP the local files & Export mysql database
- upload zip to server -> unzip it
- upload db to phpmyadmin
- Change database credentials in Config File
- run
composer install
(I also tried:composer install --no-dev
) - Done
I have repeated this procedure for several times now but its still not working
3
Answers
I have just tried to do the same thing and it seems work, check this:
/index.php
/App/Config.php
This is case sensitivity problem – your autoloading rules uses
app
as directory name, but this is actuallyApp
. 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: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:
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.