Question

error 500.autoload problem PHP-MVC

  • Posted on May 21, 2020
  • PHP
  • FLPAsked by FLP

hi, im trying to deploy my php-mvc app and i cant get my autoload.php to work. Everything works correctly on localhost, but when deploying on the server it gives me 500 (Internal error server) … I have tried to edit the apache files, activate mod_rewrite and leave everything configured to have friendly routes and still get the same problem. Apparently the code of my index.php is not working. Can anyone help? Thanks! sorry for my english

I attach my code and the apache error log:

autoload.php

<?php

function controllers_autoload($classname){
    include 'controllers/' . $classname . '.php';   
}

spl_autoload_register('controllers_autoload');

index.php

function show_error(){
    $error = new errorController();
    $error->index();
}

if(isset($_GET['controller'])){
    $nombre_controlador = $_GET['controller'].'Controller';
}elseif(!isset($_GET['controller']) && !isset($_GET['action'])){
    $nombre_controlador = controller_default;
}else{
    show_error();
    exit();
}

if(class_exists($nombre_controlador)){
    $controlador = new $nombre_controlador();

    if(isset($_GET['action']) && method_exists($controlador, $_GET['action'])){
        $action = $_GET['action'];
        $controlador->$action();
    }elseif(!isset($_GET['controller']) && !isset($_GET['action'])){
        $action_default = action_default;
        $controlador->$action_default();
    }else{
        show_error();
    }
}else{
    show_error();
}

.htaccess

<IfModule mod_rewrite.c>
# Activar rewrite
RewriteEngine on
ErrorDocument 404 http://ip/psweb/error/

RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f

RewriteRule ^(.*)/(.*) index.php?controller=$1&action=$2

# DirectoryIndex index.php
</IfModule>

error.log

PHP Warning:  include(controllers/homeController.php): failed to open stream: No such file or directory in /var/www/html/psweb/autoload.php on line 4

PHP Warning:  include(): Failed opening 'controllers/homeController.php' for inclusion (include_path='.:/usr/share/php') in /var/www/html/psweb/autoload.php on line 4

PHP Warning:  include(controllers/errorController.php): failed to open stream: No such file or directory in /var/www/html/psweb/autoload.php on line 4

PHP Warning:  include(): Failed opening 'controllers/errorController.php' for inclusion (include_path='.:/usr/share/php') in /var/www/html/psweb/autoload.php on line 4

PHP Fatal error:  Uncaught Error: Class 'errorController' not found in /var/www/html/psweb/index.php:18\nStack trace:\n#0 /var/www/html/psweb/index.php(46): show_error()\n#1 {main}\n  thrown in /var/www/html/psweb/index.php on line 18

Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Accepted Answer

the error was that linux is case sensitive xD

KFSys
Site Moderator
Site Moderator badge
May 22, 2020

Hi @FLP,

Looking at the errors you’ve provided, it seems like the following is the actual problem :

PHP Fatal error:  Uncaught Error: Class 'errorController' not found in /var/www/html/psweb/index.php:18\nStack trace:\n#0 /var/www/html/psweb/index.php(46): show_error()\n#1 {main}\n  thrown in /var/www/html/psweb/index.php on line 18

It seems like it can’t find the errorController(); class. It’s possible somewhere in your code you are not extending it. I’ll recommend checking where exactly are you including the file which holds the said class.

Regards, KDSys

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel