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
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!
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.
the error was that linux is case sensitive xD
Hi @FLP,
Looking at the errors you’ve provided, it seems like the following is the actual problem :
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