CI in apache userdirs (domain.com/~user/public/ci) |
Hello,
I operate a shared hosting environment on Ubunutu 20 for a course I teach. Each student of the course is allocated a user account with a ~/public/ directory for development. I am having difficulty getting CI4 to find controllers properly when the starter app is installed into a subdirectory of a user's public directory. The directory structure looks like this: /home/username/public/ci4/app | system | public | etc. The url for the app then looks like: http://domain.com/~username/ci4 This "works" insofar as apache is serving code igniter. However, CI throws a 404: Quote:Controller or its method is not found: \App\Controllers\~username::ci4 So this is a routing issue? I have set the base url in .env and tried adjusting the rewrite base in ~/public/ci4/public/.htaccess with various permutations of the url. How do I get CI to use the correct base for routing in this situation? Thanks! Evan
The “public/index.php” has a path set to “app/Config/Paths.php”. Try making the relevant path adjustments in Paths.php
(03-18-2021, 04:05 PM)John_Betong Wrote: The “public/index.php” has a path set to “app/Config/Paths.php”. Try making the relevant path adjustments in Paths.php Hi John, Thanks for the quick reply! I don't think the solution is in Paths.php. Nothing about the framework structure is being changed and components not found, just the install location. The Paths.php entries are all relative system paths and they are all still correct. Meanwhile, the 404 I'm getting is the CI-generated 404 page. So the framework is being located by apache ok, bootstrapped, and launched without issue. I think the issue has to do with routing. The 404 page says that the router is interpreting the url segments incorrectly by not applying the specified base url; it is interpreting the apache userdir "subdirectory" as the requested controller. Note that I'm using this apache module: https://httpd.apache.org/docs/2.4/mod/mod_userdir.html What else could confuse the router this way if I've already set the baseurl variable (in .env) and adjusted the ../ci4/public/.htaccess BaseRewrite? Quote:The directory structure looks like this: /home/username/public/ci4/public/.htaccess Code: # Disable directory browsing /home/username/public/ci4/app/Config/App.php PHP Code: <?php 404 error page source: Code: <!DOCTYPE html>
Check on the user guide directory structure. Normally the app, system and writable directories are all above the base directory.
It appears as though your directory structure has these three directories below the base directory. CodeIgniter4 can be configured that way but it is not recommended.
I appreciate you continuing to look at my question John.
By "base" do you mean the web root being served by apache? If you take a closer look at the the system paths I listed, there are two "public"s in the mix. The higher one is in the user's home directory and it the target of mod_userdir rewriting - it is effectively the web root. The lower "public" is CI's exposed assets directory. Since the URL is resolving and CI is bootstrapping just fine, I am still pretty sure this is not a framework path issue, since then wouldn't the whole thing not run? Where does the router class get the base from which to separate the controller and method segments of the url? Why is setting baseUrl (/app/Config/App.php) and RewriteBase (public/.htaccess) not doing the trick? Earlier today I went ahead and changed all the mod_userdir targets to be "~/www" instead of "~/public" is case the two publics were choking mod_rewrite. The CI router still isn't resolving controllers properly so that wasn't it. Considering your suggestion further, if I looked at how to place app/ sys/ writeable/ etc. above ~/www/ (directly in the user's home directory) encapsulating the instance into a git repo would get messy. Part of the reason I'm trying to have students be able to simply composer-install the starter app into a subdirectory of their personalized web root is so that they can use git to collaborate and submit work to me.
Can you add this DEBUG script to index.php immediately before $app->run(); and show what is displayed.
file: index.php Code: # DEBUG =======================================================G Also can you confirm that the CI4 Splash screen is loading.
Paths.php is unmodified.
Quote:index.php ==> /home/kaimartin/www/hiperplanner/public/index.php The splash has never loaded correctly. My test project has shown a 404 from the beginning. As I said though, it is the CI 404 that references url segments as controllers, not apache's 404. I've never tried to use the output of __DIR__ in a variable like the Paths config does; should it be resolving the parent entry before setting the $paths value?
Quote:@evansharp, I was confused and thought "This "works" insofar as apache is serving code igniter." that the splash screen was working Can you go into the command Prompt and check each directories and contents are correct: // COMMAND PROMPT Code: # GOTO EACH DIRECTORY Hopefully the Splash screen should now show.
These paths have been correct and I had already set the permissions on writable/
Code: root@webserver:/home/kaimartin/www/hiperplanner# ls The default paths from Paths.php resolve correctly: Code: root@webserver:/home/kaimartin/www/hiperplanner# cd /home/kaimartin/www/hiperplanner/app/Config/../Views The welcome view still does not display since the router still can't distinguish the install directory from the controller URL segment. What are you thoughts on the RewriteBase directive of the public/.htaccess? FollowSymLinks are enabled. This is the current config: Code: <IfModule mod_rewrite.c> Could the default CI rewrite scheme be fighting with mod_userdir? My rewrite-fu is limited. There are plenty of CI3-era posts about this, but they all recommend doing what I've done: set the RewriteBase to include the userdir.
Quote:@evansharp, .htaccess is not required in order to display the Splash Screen. I think the main purpose of .htaccess is for apache2 redirection of Pretty Urls. Without a .htaccess file apache2 is usually set so that index.php is called first and this in turn calls CodeIgniter4. Please temporarily rename .htaccess to something like .htaccess-ORIGINAL The .htaccess file instructions maybe preventing CodeIgniter4 from rendering the Splash Screen. Errors are usually logged in Ubuntu's /var/www/log/apache2/errors.log If the Splash Screen is still not rendering then add echo __file__; die; to the following files and see if they are being called: ./app/Config/Routes.php ./app/Controllers/BaseController.php ./app/Controllers/Home.php |
Welcome Guest, Not a member yet? Register Sign In |