CodeIgniter Forums
File not found on my online server - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: File not found on my online server (/showthread.php?tid=90833)

Pages: 1 2


File not found on my online server - Kobbs - 05-10-2024

Hi, I've been trying to solve my problem all day but I haven't been able to solve it. Locally, my site works fine when I browse it. But on my online server, when I try to access the mywebsite.com/test page it gives me this error: File not found.

Routes.php

PHP Code:
<?php

use CodeIgniter\Router\RouteCollection;

/**
* @var RouteCollection $routes
*/
$routes->get('/''Home::index');
$routes->get('test''Home::mytest'); 

Home.php

PHP Code:
<?php

namespace App\Controllers;

class 
Home extends BaseController
{
    public function 
index(): string
    
{
        return 
view('welcome_message');
    }

    public function 
mytest()
    {
        echo 
"test...";
    }



All my files (app, public, tests, vendor, writable, etc.) are in the root of my server in the ‘www’ folder.

Thank you in advance for your help.


RE: File not found on my online server - kenjis - 05-10-2024

Do you use nginx?
It seems your have something wrong with your web server configuration.


RE: File not found on my online server - Kobbs - 05-10-2024

I use a shared server from OVH.


RE: File not found on my online server - kenjis - 05-10-2024

See https://codeigniter4.github.io/CodeIgniter4/installation/deployment.html#deployment-to-shared-hosting-services

But if your hosting service provides nginx, the user guide may not help you.


RE: File not found on my online server - Kobbs - 05-10-2024

I did as explained in this guide (first (and best) solution), I have a folder at the root of my server under the name www, which contains all the project files. And I've changed the root folder in the server settings so that it points directly to the public folder. I can try the other solutions suggested, but I don't understand why the first solution doesn't work.

I've just tried the other two solutions (with two directories, and using .htaccess) and the site still works, but the epas37.com/test route still doesn't work.


RE: File not found on my online server - InsiteFX - 05-10-2024

You may need to change app/Config/App.php
PHP Code:
    /**
    * --------------------------------------------------------------------------
    * URI PROTOCOL
    * --------------------------------------------------------------------------
    *
    * This item determines which server global should be used to retrieve the
    * URI string. The default setting of 'REQUEST_URI' works for most servers.
    * If your links do not seem to work, try one of the other delicious flavors:
    *
    *  'REQUEST_URI': Uses $_SERVER['REQUEST_URI']
    * 'QUERY_STRING': Uses $_SERVER['QUERY_STRING']
    *    'PATH_INFO': Uses $_SERVER['PATH_INFO']
    *
    * WARNING: If you set this to 'PATH_INFO', URIs will always be URL-decoded!
    */
    public string $uriProtocol 'REQUEST_URI'


Also your server maybe case sensitive so you would need to use all lower case file names.


RE: File not found on my online server - Kobbs - 05-10-2024

The default value was already REQUEST_URI. I also tried as advised to leave my file names in lower case (Home.php -> home.php) and by modifying my Routes.php file (Home::mytest -> home::mytest), the site is still operational but still returns the ‘File not found’ error when I try to access the epas37.com/test route.


RE: File not found on my online server - kenjis - 05-11-2024

What is your web server software?


RE: File not found on my online server - kenjis - 05-11-2024

(05-10-2024, 11:57 PM)Kobbs Wrote: I also tried as advised to leave my file names in lower case (Home.php -> home.php) and by modifying my Routes.php file (Home::mytest -> home::mytest),

The change is wrong. You should not do like that.
You must name the file in the exact same case as the class name.
Because filenames in most servers are case sensitive.

E.g.,
1. if the classname is Home, then the file name must be Home.php
2. if the classname is home, then the file name must be home.php.


RE: File not found on my online server - Kobbs - 05-11-2024

(05-11-2024, 01:11 AM)kenjis Wrote:
(05-10-2024, 11:57 PM)Kobbs Wrote: I also tried as advised to leave my file names in lower case (Home.php -> home.php) and by modifying my Routes.php file (Home::mytest -> home::mytest),

The change is wrong. You should not do like that.
You must name the file in the exact same case as the class name.
Because filenames in most servers are case sensitive.

E.g.,
1. if the classname is Home, then the file name must be Home.php
2. if the classname is home, then the file name must be home.php.

Basically, my Home.php file contains the Home class (in upper case). When I modified it, I forgot to change the case, but unfortunately the problem remains the same.
If you want, I can put my project on github?