404 with Codeigniter 3 on LAMP, but however working on MAMP - php

I started a new project on CI3.
I developed it on my MB with MAMP. Everything works fine !
This afternoon I tried to publish the code on my VM serveur ( Ubuntu 18.04, php 7.2.19 ).
The welcome page works good, but impossible to use a routes.
localhost/index.php -> good
localhost/index.php/push/ -> 404 ( still working on MAMP )
I tried to use an .htacces, create a route in router.php file, ....
/application/controllers/api.php :
class Push extends REST_Controller{
public function _construct(){
....
}
public function index_post(...){
...
}
}
always a 404 NOT FOUND on LAMP only

The problem is that the Mac OS is case insensitive, but the Linux OS is case sensitive. CodeIgniter requires that file and class names match exactly and that they have an uppercase first character in the name with all other characters being lowercase. On a case insensitive system you can get away with ignoring that convention, but on a case sensitive system you cannot.
BTW, it is Controllers, Models, and Libraries that are case sensitive. In essence, any file that defines a PHP class.

Related

Codeigniter site working in MAMP but not LAMP

I am using MAMP to locally host my codeigniter project. Each of my controllers extends MY_Controller. MY_Controller looks like the following:
class MY_Controller extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->model('user_model');
$this->user_model->do_something();
}
}
Using MAMP, on my macbook, this works fine. However, when I upload my site to my linux server running apache, I get the following error:
Unable to locate the model you have specified: User_model
Why?
UPDATE
I changed the capitalization to be like this:
$this->load->model('User_model');
$this->User_model->do_something();
and the problem continues
Linux is a case-sensitive operating system, and as such you need to be really careful when developing on Windows and deploying to Linux.
Your issue stems from the line :
$this->user_model->do_something();
Which should be :
$this->User_model->do_something();
As it is the name of an object you are trying to access.
The line which loads it is fine, as CodeIgniter doesn't mind which case you use to load the models, but PHP will get somewhat picky on Linux when it comes to names of things.

CakePHP 3.0 not running on other machines

I've developed a small project on a machine, using CakePHP 3.0, and I need it to run on another machine. I've tried to install it on several other machines.
If I run the composer to install the CakePHP 3.0, then I copy my stuff to overwrite it, the project works. I've tried this on two machines and had no problem so far. If I don't run the composer, and just copy the stuff to the target machine, it gives me the following error. I've tried this on 3 machines, and every machine gives me this:
Fatal error: Class 'Locale' not found in /home/u113681897/public_html/vendor/cakephp/cakephp/src/I18n/I18n.php on line 229
Fatal error: Class 'Locale' not found in /home/u113681897/public_html/vendor/cakephp/cakephp/src/I18n/I18n.php on line 229
I've copied the whole project to this server to test.
I told you this because I thought it has something to do with my problem. The point is that I have to run this on a machine that is not mine, and I can't install composer on it. The /public_html/vendor/cakephp/cakephp/src/I18n/ has files related to internationalization and localization, but my project will never be translated, so a workaround to make the project ignore those files would be enough to solve my problem.
The following code is an excerpt from the (...)/I18n/I18n.php that might be relevant:
<?php
namespace Cake\I18n;
use Aura\Intl\FormatterLocator;
use Aura\Intl\PackageLocator;
use Aura\Intl\TranslatorFactory;
use Cake\I18n\Formatter\IcuFormatter;
use Cake\I18n\Formatter\SprintfFormatter;
use Locale;
class I18n {
// lots of code here
public static function defaultLocale() {
if (static::$_defaultLocale === null) {
static::$_defaultLocale = Locale::getDefault() ?: 'en_US';
// the line above is the Line 229
}
return static::$_defaultLocale;
}
// many code here too
}
I've checked that another file also tries to access this Locale class, but I don't know if there are other files trying to access it as well. Many files from everywhere inside the project tries to access methods from I18n.php. I need it running but I can't figure out how to make it run.
Any help will be greatly appreciated.
As I just found out, prior to CakePHP 3.0, the installation must be done by composer, as stated in the 3.0 migration guide:
CakePHP should be installed with Composer
Since CakePHP can no longer easily be installed via PEAR, or in a shared
directory, those options are no longer supported. Instead you should use
Composer to install CakePHP into your application.
So it won't run on regular free web hosting services.

Kohana 3.3 model Class Not Found error only in php 5.5.3

I am writing a Kohana app that has been dev'd locally on Ubuntu 12.04 LTS (PHP 5.3). It works without issue in this environment, but it throws a fatal error whenever it tries to autoload a classes/Model class on the production server (which is Ubuntu 13.10 running PHP 5.5). The application code is exactly the same. The only difference I could mention is that the apache vhost conf uses the Require directive instead of the Allow/Deny syntax because Ubuntu 13.10 ships with newer version of apache.
I get the following error whenever I hit a controller action that needs to load a model:
ErrorException [ Fatal Error ]: Class 'Model_Event' not found
MODPATH/orm/classes/Kohana/ORM.php [ 46 ]
Interestingly enough, Kohana is evidently able to load the controller classes I wrote without issue.
[source root]/application/classes/Model/Event.php exists and is ugo+rx (as are the parent directories). It contains a valid class definition (this works without issue on my local 12.04/5.3 environment). 'head -n2 [source root]/application/classes/Model/Event.php' is:
<?
class Model_Event extends Model_BaseModel {
I know PHP 5.5 introduced a difference in how it does case-insensitive string comparisons, but the file/folder names and class names are an exact case match so this shouldn't be an issue here.
PHP wasn't respecting the "short_open_tag = On" ini setting.

Zend Framework: Model class not found

The following exception is thrown on my server:
Fatal error: Class 'My_Model_Bo_User_Agenda_Doctors' not found in...
Though in localhost everything is working fine.
I checked that everything was correctly uploaded; all the files are present and not corrupted. I also tried to upload several times. So this doesn't seem to be the problem.
Any idea why a class couldn't be found on the server ?
You don't say so in your question, but I suspect that you are developing on windows and hosting on Linux.
Windows is not case sensitive to path names, but Linux is! Check that:-
Doctors.php is not doctors.php
Agenda/ is not agenda/ .etc
Lastly check the class name in the class declaration is correct and correctly cased.
Do not just think to yourself, yes I've done that, go and check them carefully. Believe me, bitter experience has taught me this problem is always due to a trivial oversight like this.

ZendFramework 1.11.3: 'Plugin by name 'Jquery' was not found in the registry

I have two servers.
snow leopard on HFS (case-insensitive) file system
gentoo linux with ext4 (case-sensitive) file system
on both of them I use php 5.3 and latest apache2 and latest Zend Framework 1.11 build.
under Mac OSX the website works properly, under linux I have the following error:
Fatal error: Uncaught exception 'Zend_Loader_PluginLoader_Exception' with message 'Plugin by name 'Jquery' was not found in the registry; used paths: Dashboard_View_Helper_: /home/ufk/Projects/php-projects/xpo-website/application/modules/dashboard/views/helpers/ xpo_Uploadify_View_Helper_: xpo/Uploadify/View/Helper/ ZendX_JQuery_View_Helper_: ZendX/JQuery/View/Helper/ : /home/ufk/Projects/php-projects/xpo-website/application/helpers/ Zend_View_Helper_: Zend/View/Helper/' in /usr/local/ZendFramework-1.11.3/library/Zend/Loader/PluginLoader.php:412 Stack trace:
0 /usr/local/ZendFramework-1.11.3/library/Zend/View/Abstract.php(1174): Zend_Loader_PluginLoader->load('Jquery')
1 /usr/local/ZendFramework-1.11.3/library/Zend/View/Abstract.php(610): Zend_View_Abstract->_getPlugin('helper', 'jquery')
2 /usr/local/ZendFramework-1.11.3/library/Zend/View/Abstract.php(336): Zend_View_Abstract->getHelper('jquery')
3 /home/ufk/Projects/php-projects/xpo-website/application/modules/dashboard/views/scripts/game/login.phtml(1): Zend_View_A in /usr/local/ZendFramework-1.11.3/library/Zend/Loader/PluginLoader.php on line 412
I copied the ZendX directory (from extras/library) to the library directory of the Zend Framework located at /usr/local/ZendFramework/library/ZendX/.
I initialize the helper using:
ZendX_JQuery::enableView($view);
the code inside login.phtml that is causing the exception is:
$this->jquery()->enable();
it shouldn't even relate to the code itself because under the Mac OS server it does work, but i do have ZendX here too so i can't pinpoint the problem.
Not able to test right now, but suspect you need to uppercase the 'q' in jQuery in this line:
$this->jQuery()->enable();
Typically ZF maps methods to class names by uppercasing the first letter, so could be the 'unusual' uppercase Q in the class name is the problem.
You have to add the helper path. See manual. You can do that in bootstrap, using Zend_Application, using FrontController plugin, in base controller class or directly in view.
Update: Sorry I misread your question. The problem IS the small "q". Windows is case insensitive. That's why it works there. Linux is not. So 'jQuery.php' and 'jquery.php' are not the same files.

Categories