CodeIgniter MY_Controller not working in web server - php

I extended the CI_Controller and made my own controller to be extended.
Now everything works fine in localhost (xampp) but when I copied the files over to my web server, I get 500 internal server error which is quite useless. Odd to me is the fact, that I get internal server error instead of codeigniter generated error.
Things I have tried so far:
1) tried libraries folder instead of core for MY_Controller
2) I have had problem with server only accepting lowercase file names so I tried my_controller and changing config file prefix, main.php extension and so on.
Both of these seems like useless tries anyways, cause I didn't get error saying it can't be found or something similar.
When I change my main.php controller to extend CI_Controller, everything works fine.
I know I haven't provided much information, but I have no idea what to provide. Again, it works in localhost.
Thanks for any input you might have.

Try changing your config.php to.
$config['index_page'] = '';
and the .htacces of the site to:
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/system.*
RewriteRule ^(.*)$ index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?/$1 [L]

Related

live server shows 404 error, but not on local, codeigniter 3

I have four identical pages that only differs in some identifiers but the logic is very much the same. All of them works on localhost. Three of those pages works okay on live server, but one of them returns a 404 for some reasons I can't understand.
I use XAMPP 3.2.2 and Sublime for developing it on local. I moved it to GoDaddy Deluxe Linux for live. My Codeigniter version is 3.1.10.
I already tried answers from most of the questions on StackOverflow:
All controller and model names' first letters are capitalized in the file name and inside the file.
All of the .htaccess codes on here: https://github.com/tasmanwebsolutions/htaccess_for_codeigniter
I have two .htaccess files, one of them is inside the application folder, and one is outside. I don't know if that's confusing the system? But I have another website on a different hosting that has the same .htaccess files and they're working okay. And anyway, if that's confusing the system, why does it only affect one of the four identical pages?
.htaccess outside application folder
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>
.htaccess inside application folder:
<IfModule authz_core_module>
Require all denied
</IfModule>
<IfModule !authz_core_module>
Deny from all
</IfModule>
All of the controllers of the four files has this up top:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
//session_start(); //we need to call PHP's session object to access it through CI
class Question1 extends CI_Controller
{
and the rest is normal code stuff that are working on three of those four files.
In config. php I have:
$config['uri_protocol'] = 'REQUEST_URI';
and base_url is great.
Models and views are okay, as far as I can see, and the rest of the website is functioning alright with the included .htaccess. My routes are working okay, as well.
I'm so lost right now.
PS. I have a custom 404 page. When I input assessment.com/index.php/question1 it shows that custom 404 page. But when I open assessment.com/question1 it shows codeigniter's own 404 page (and not my custom one, for some reasons). I think that tells something, I just don't know what.
EDIT
Here's my routes.php:
$route['default_controller'] = 'home';
$route['404_override'] = 'Error404';
$route['translate_uri_dashes'] = TRUE;
I opted not to do
$route['question1'] = "Question1";
in routes because it doesn't change anything.
Check your APPLICATION ENVIRONMENT mode. You can find it on your project root_folder/index.php and at line no. 57.
define('ENVIRONMENT', 'production');
Change the ENVIRONMENT mode into the development mode, that is
define('ENVIRONMENT', 'development');
Then refresh your applications again. If you see CodeIgniter default error you can understand your CodeIgniter application are running ok and check out the error.If it doesn't show any error then your .httaccess has any error. I solved it my 404 error with this code, you can check this out.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_URI} ^asset.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
Answering this for the others who might come across the same problem.
Okay so user Don't Panic suggested I echo just "question x" in the problematic controller, and when I did that, the 404 error went away and it echoed the "question x." So definitely it's my controller that has the problem and not my routine or .htaccess files.
Now this controller is designed in such a way that it calls first an ID from the database before it shows anything. After I echoed "question x" I realized that the ID it is calling from my database has a value of zero. So, unsurprisingly, from the controller's point of view, the page doesn't exist! Hence the 404.
I've fixed it now by updating that table from my database and giving the ID a value it should already have had in the first place.

Codeigniter return not found on the server

I just uploaded my application into another server (worked well on the previous), but now I get this error:
Not Found
The requested URL /lk/installation was not found on this server.
I suspect that there are some issues with the .htaccess which have the following content:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
the controller installation is declared as: Installation.php, but I repeat, the application worked well on the previous server so there aren't technical problem like class name declaration or something like. Must be a problem of configuration of the server, noticed that I get not found with the server page not CodeIgniter page.
It might be a name declaration problem if the previous server was Windows and the new one is Linux. Windows is not case sensitive, but Linux is case sensitive.
So Installation.php must define the class using uppercase first e.g
class Installation extends CI_Controller {
The other thing to test is that .htaccess is working - assuming you use it. If you are and this URL fails
https://example.com/installation
But this URL works
https://example.com/index.php/installation
Then .htaccess isn't working as expected.

Routes in Codeigniter not working on different server

Let me inform you this first. This application is working pretty fine on live server currently, however we needed to move it to a different server with a different domain.
Issue is: It gives 404 error on every other page except for index. Loading through index.php works fine.
For an example:
www.test.com/main/login //This gives 404 error
www.test.com/main/index.php/login //This loads fine
Because everything is working fine currently, I made changes only in $config['base_url'] and in database config file. There have been no other changes in any of the files.
Also, this solution provided by somebody in a different questions is already tried out and this doesn't work. Solution is to create .htaccess file with below code & setting $config['index_page']='' :
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
Current server is VPS & provider is GoDaddy. New server is Shared hosting and provider is GoDaddy. I'm not getting the root cause of this happening, can somebody point out to the possible solution?
EDIT
I'm attaching a screenshot for an error, it's not typical 404 error page. In case this helps.
For Godaddy, you need to alter this 2 things.
In your .htaccess file, replace
RewriteRule ^(.*)$ index.php/$1 [L]
With the following:
RewriteRule ^(.*)$ index.php?/$1 [L]
Then is your application/config/config.php :
$config['index_page'] = '';
Both this changes should help you resolve your issue.

Selective 404 error on CodeIgniter installation

I copied a fully functional CodeIgniter app into a new server, updated the config.php base url, and setup all database parameters accordingly.
An interesting problem I'm having is that the new install (in new server) returns a 404 for all controllers I try to access. However, when navigating to the base URL, my default controller welcome.php defined in routes.php is rendered fine on the browser.
$route['default_controller'] = "welcome";
This suggests to me that CI is running OK but there may be some other routing issue I'm not figuring out.
My .htaccess is
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
which works fine on the other server.
Any ideas what I'm doing wrong here?
Is your apache directory configuration set to AllowOverride All?

ZF2 Fatal error AbstractActionController not found on shared host

I developped my app localy (where it runs fine) and wanted to upload it to a shared host to test it.
Now I get an Fatal error that says the Zend DefaultController is not found when I go to any page on my app, only the index page works... The indexcontroller also extends Default controller as my other controllers does.
the test version is visible on tbox.ues.ch, this page will work but when you go to tbox.ues.ch/tender for example it throws the error.
my code on this line is simply
use Zend\MVC\Controller\AbstractActionController ;
class TenderController extends AbstractActionController
{...
nothing special like you can see
I'm using zendskeletonapplication and my .htaccess at root folder contains
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/public/.*$
RewriteRule ^(.*)$ /public/$1
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^public/.*$ /public/index.php [NC,L]
I already searched arround, tried out several htaccess configuration, but didn't find a solution. Problem is still the same, even if I access my app on tbox.ues.ch/public with the default .htaccess from ZF2
Does somebody has any Idea?
Just found my error...
I changed Zend\MVC... to Zend\Mvc... uppercase problem
But I find strange that it works on my localhost and not on my shared host, anyway now I know from where comes my problem

Categories