How to use PHP with MVC pattern on 000webhost?

I implemented a simple MVC pattern on my site and it works fine on my pc using XAMPP. Now I want to host the site here but had some problems. This GitHub respository shows how my files are organized on 000webhost file manager.

  1. Should I put ALL files inside the public_html folder (including models, views, controllers) or only the general MVC public content (primary index.php, css, js…) like I did?
  2. Why am I getting the following error when oppening the site?

Warning: require_once(…/app/controllers/home.php): failed to open stream: No such file or directory in /storage/h6/242/1091242/app/core/App.php on line 20

Your app structure can be as it is in github repository. What you need to fix is the relative path to the files.

Try changing this line https://github.com/guizoxxv/my-mvc/blob/master/public_html/index.php#L3

to require_once __DIR__ . '/../app/init.php';

I’ve tried your suggestion but it didn’t worked. I get HTTP ERROR 500. I can tell that the path ../app/init.php is working as the error occurs at app/core/App.php line 20 which is a file required in init.php.

I discovered the problem. The path ../app/controllers/home.php does not find the file because the file is Home.php (uppercased H). I didn’t realized this because it works fine in my pc with XAMPP. I believe that XAMPP’s Apache is configured in a way that allows case insensitive URLs which does not happens in 000webhost and I don’t know how to do it.

Thank you.

000webhost is linux servers and it cares about lowercase and uppercase file names. So make sure your are using correct ones.