Welcome Guest, Not a member yet? Register   Sign In
VM vs Docker routing problem
#1

(This post was last modified: 04-30-2023, 09:56 AM by nuke. Edit Reason: Add detail )

Hello folks,

I have a strange one for you today.
I have a CI 4.3.3 site that was developed on a VM and works correctly.
I copied the app, public, tests, writable, and modules folder over to a docker container. Ran the composer install and can access the front page, but when I visit any other page I get trouble.

Visiting http://example.com works as expected
The site was setup to serve static pages like the News example (and worked on the VM)
route for get('(:segment)', 'Main::index')

Visiting http://example.com/home returns a html page with only 'File not found' text and sometimes a page with 'NOT FOUND The requested URL was not found on this server.' (Neither are the CI 404 page)

Visiting http://example.com/index.php/home gives me the CI 404 page but with a message of "Controller or its method is not found: \Config\Main::index"

My thoughts were that:
- the first request works because the DocumentRoot is /var/www/html/public and there is an index.php (set by DocumentIndex) in that folder.

- the second did not work because something was wrong with the .htaccess rewrite, so
    1. Checked a2enmod rewrite - returned as already enabled
    2. Checked that AllowOverride All, Options +FollowSymLinks, Require all grant were present in Apache config - they are.
    3. Checked the .htaccess file was being used by adding jibberish text to the file outside the ifModule and got an expected 500 response
    4. Put the jibberish inside the ifModule and got the same 500 response
    5. Commented out everything except the rewrite for removing the index.php from the URL - Same results
    6. Checked .env got loaded by echoing out print_r($_ENV) and app.indexPage = '' is present, even went so far as to change the value in Config/App but same result
    7. I can create a home.php in the public folder and call the http://example.com/home.php and it works to display that file (apparently without a route and not going through index.php)

- the third request led me down something amiss in the Config/Paths route. I cannot figure out why it is looking in the Config folder for the Controllers
    1. Checked the namespace on the Main controller and it is App\Controllers

I have tried removing the get('/', 'Main::index") route and the first request then fails, so routing seems to be working

I have tried many routes for the static page
- get('(:segment)', 'Main::index')
- get('(:any)', 'Main::index')
- get('home', 'Main::index')
- get('(:segment)', ['Main::class, 'index'])
- get('(:any)', ['Main::class', 'index'])
- get('home', ['Main::class', 'index'])

Nothing seems to change

I have Shield installed and with its routes included, when I call
1. http://example.com/login I get 'file not found'
2. http://example.com/index.php/login displays the login form
3. Attempting to access protected folder controllers redirects to login as expected

Being the change was VM to Docker image, it kind of pointed to a server setup but they seem to all checkout.
One difference is the VM is using Mod-PHP and the Docker is using PHP-FPM

I'm kind of at a loss and any suggestions of what to check or how to troubleshoot are appreciated.
Reply
#2

Problem was caused by the use of PHP-FPM.

Apparently it doesn't use the rewrite to remove the index.php

Solution was to replace


Code:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,NC,QSA]


with

Code:
FallbackResource /index.php
Reply




Theme © iAndrew 2016 - Forum software by © MyBB