Report this

What is the reason for this report?

error 500.autoload problem PHP-MVC

Posted on May 21, 2020
FLP

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

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Start building today

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.