Tutorial first app issues when not installed in doc root |
Folks,
New to CodeIgniter 4, used earlier versions and really liked it. I'm doing a clean install using Composer and pretty much following the Manual/Tutorial directions. All seemed well, but having problem with the ci-news demo app and generated URLs. I see several areas where URLs can be adjusted, but I don't want to fight it and would like a clean solution. My setup: Web server doc root /pub/comwww/soaringtools - www.soaringtools.org [don't want to change that, existing site] Tutorial Steps: Installed in the directory: /pub/comwww/soaringtools/ci-news using composer and moved dirs as recommended. (contents) app/ builds* composer.json composer.lock license.txt phpunit.xml.dist public/ README.md spark* tests/ vendor/ writable/ Followed the tutorial, updated Routes.php as directed, no changes to Paths.php, no changes to .htaccess in public directory, edited the .env file to set DEVELOPMENT and DB access info, no change to baseURL What works now: https://www.soaringtools.org/ci-news/public -- brings up the Welcome to Codeigniter OK https://www.soaringtools.org/ci-news/public/home or about-- brings up those pages OK https://www.soaringtools.org/ci-news/public/news -- brings up the news summary page OK, but "View article" links are wrong. They generate the URL -> https://www.soaringtools.org/ci-news/pub...is-sighted instead of -> https://www.soaringtools.org/ci-news/pub...is-sighted (which does work) [url=https://www.soaringtools.org/ci-news/public/news/elvis-sighted][/url] Can this be adjusted/fixed simply? Do I need to move the public directory? I want the final URLs to start with: https://www.soaringtools.org/ci-news/new ... (no public) I see adjustments possible in: ci-news/public/.htaccess - use RewriteBase as suggested there, but to what? ci-news/.env - change the value of app.baseURL, to what? ci-news/app/Config/Paths.php -- change systemDirectory or appDirectory, both? -- or do I just need to adjust the generated paths in the view directly. Any help is welcome. I'm trying to avoid forcing it by using the wrong methods. Many Thanks! John
Hi, are you sure you put the correct url here?
Code: <p><a href="/news/<?= esc($news_item['slug'], 'url'); ?> As /news/ are not something that get's automatically get set. Just to make sure, you want https://www.soaringtools.org/ci-news/public to become https://www.soaringtools.org/ci-news ? If so, this needs to be set in .env Code: app.baseURL = https://www.soaringtools.org/ci-news/ And for removing "public" you can follow these instructions: https://forum.codeigniter.com/thread-759...#pid373901 To summarize; Rename "public" into "ci-news". All other files and folders need to be moved here: /pub/comwww/ci-news /pub/comwww/soaringtools/ci-news/index.php PHP Code: $pathsPath = FCPATH . '../../ci-news/app/Config/Paths.php';
OK, many thanks! Really appreciate the quick response!
I got it working with the following changes as you suggested: Moved everything up one directory from public into /pub/comwww/soaringtools/ci-news Code: [soaringtools@torch ci-news]$ pwd You were correct, I had missed part of the path needed in the overview.php, but I also had to change it to './news/' Code: [soaringtools@torch ci-news]$ git diff Also made the change to the index.php, slightly different path, matches dir contents: Code: --- a/index.php All now works well!: https://www.soaringtools.org/ci-news/about https://www.soaringtools.org/ci-news/news -- and the links to the messages work great!
Hi, for a security point of you. It's wrong I'm afraid. Your index.php should not be together with all other files.
I can now access your notes: https://www.soaringtools.org/ci-news/notes.txt Those folders need to be moved two directories up, please take a second look at my description.
OK, well that was a surprise! I did move all the other folders/files into the higher directory, outside of the webserver doc root. I adjusted the path in the index.php and all is well!
I would like to know how you detected the notes.txt file -- there was no directory indexing active? Also, one other change I 'think' was needed involved the create news item view: app/Views/news/create.php The original 'action' according to the tutorial was: <form action="/news/create" method="post"> I had to change it to the below: <form action="<?=site_url()?>/news/create" method="post"> Again, many thanks for the help! John
Based on your notes in your previous post, you only moved public/index.php to index.php. You did not move anything else.
Making: https://www.soaringtools.org/ci-news/public/index.php Into: https://www.soaringtools.org/ci-news/index.php But all other folders and files are still here: https://www.soaringtools.org/ci-news/app https://www.soaringtools.org/ci-news/vendor ... That's why I suggested to move those folder two steps down as well. So you can't access them with any url. It looks like you have done so know, at least I can access them any more. You copied your "dir" command, and listed notes.txt as a file. ________________________ You should change that into <?= site_url('news/create'); ?>, makes it look nicer at least. :-)
OK, thanks for all the help. I wanted to summarize below to make it easier for folks trying to solve the same issue:
GOAL: Install Codeigniter 4.x using Composer on an existing website where you'd like the new Codeigniter application accessible via a URL referencing a sub directory, e.g. Existing website: www.yoursite.org, Apache DocumentRoot: /pub/users/you/yoursite Desire to have new Codeigniter app accessible as: www.yoursite.org/ci-news Follow the CodeIgniter 4.x install instructions for the demo app, briefly: Code: # go to your DocumentRoot NEXT - move stuff around since we want to reference via subdirectory in URL. Create a higher level directory outside the Document Root. It will hold all the application files and the Codeigniter install - inaccessible from Apache! Code: $ mkdir /pub/users/you/ci-news Almost done! Now edit a few files/permissions. Code: # Rename env to .env You should then see the Codeigniter welcome page at https://www.yoursite.org/ci-news and be able to complete the first app tutorial! |
Welcome Guest, Not a member yet? Register Sign In |