CodeIgniter Forums
index.php in the root folder? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forum-28.html)
+--- Forum: CodeIgniter 4 Discussion (https://forum.codeigniter.com/forum-31.html)
+--- Thread: index.php in the root folder? (/thread-78391.html)



index.php in the root folder? - kadirilkimen - 01-12-2021

Hi Everyone,

Documentation says :
"setting up = none"
and
"[b]pros = download and run"
[/b]

Well... I downloaded it. put it in the root folder of an xampp server with php7.4 on Windows. It didn't run.  Dodgy
I tried to setup nothing. It didn't run either.  Dodgy

I believe the documentation needs improvements.  Sleepy


However, it is not the point of this topic.

I am a CI 3 developer and I usually have small scale and straight forward projects. I like to use CI 3 because it makes my development process easier. Since it handles a lot of things that I wouldn't want to( probably also can't ) code...

I also like to be up to date and I decided to take a look at CI 4. And at the first minutes, I didn't like it. Because it says "you have to setup virtual host"... Please don't get me wrong. I am not complaining. Also I can do virtual host thing. But I am more likely an off the shelf person and don't like to do a lot of configuration on the server side. I feel like if I need to move on a new server, I wouldn't worry about if the hosting provider allows me to temper with the virtual hosts or something other stuff.

So, I simply put an index.php file on the root folder ( which is localhost/ci4/ ).

Then added only this line in it : <?php require_once('public/index.php'); ?>  Big Grin Cool

So far, it works fine. I am able to see the pages without doing any virtual host or any server configuration. I couldn't do much things on CI4 but simple things works fine. 

So, I know that there is a reason to move the index.php into the public folder. I am not quite 100% sure why, but I am sure you guys have good reasons and my index.php on the root attempt probably ignores some of this reasons. But I couldn't find another solution.


My question is ( finally ) How worse is it?  Angel

If this would lead problems ( bugs or security ), Is there any solution without tampering with server configuration. May be using .htaccess files?


RE: index.php in the root folder? - iRedds - 01-12-2021

Or maybe you can change the assembly as an option?
For example on OpenServer (https://ospanel.io/)?
There you can specify virtual hosts from the GUI.


Yes, this is not the answer you expected to hear. But I think this approach is more correct. Rather than trying to make the framework work through crutches.


RE: index.php in the root folder? - John_Betong - 01-12-2021

@kadirilkimen,

This may be of interest:

I have a localhost CI4 installation using Ubuntu with apache2:

I made the following changes:

1. renamed /var/www/ci4-stict.tk/public_html/index.php to index-001.php
2. modified /var/www/ci4-stict.tk/public_html/.htaccess -> RewriteRule ^(.*)$ index-001.php/$1 [L]
3. browsed to http://localhost/ci4-strict.tk/public_html/index-001.php

Delighted to say: splash page and all linked web-pages worked fine Smile

Edit:
I forgot to mention that I already had the following set:
Code:
// file: ./app/Config/App.php

public $indexPage = ''; //'index.php';



RE: index.php in the root folder? - iRedds - 01-12-2021

(01-12-2021, 09:24 PM)John_Betong Wrote: I made the following changes:

1. renamed  /var/www/ci4-stict.tk/public_html/index.php to index-001.php
2. modified  /var/www/ci4-stict.tk/public_html/.htaccess -> RewriteRule ^(.*)$ index-001.php/$1 [L]
3. browsed to http://localhost/ci4-strict.tk/public_html/index-001.php

Monsieur knows a lot about perversions  Big Grin


RE: index.php in the root folder? - kadirilkimen - 01-13-2021

(01-12-2021, 08:22 PM)iRedds Wrote: Or maybe you can change the assembly as an option?
For example on OpenServer (https://ospanel.io/)?
There you can specify virtual hosts from the GUI.


Yes, this is not the answer you expected to hear. But I think this approach is more correct. Rather than trying to make the framework work through crutches.

Thanks for the advice. But as you can see, I am already aware of more correct approaches, yet given more correct approaches creates problem for me. It is why I decided to post this topic. May be you would explain why my approach is not a good (at least not acceptable ).

The problem for me is not the localhost. It is easy for me to setup a vhost in xampp. Very easy. I usually use simple shared web hostings for my projects and my clients. I can't use expensive servers to install custom softwares for small scale web sites.  Sometimes I have to use whatever my client already has. And it is most likely a php&mysql shared webhosting without offering much configuration.

Because of that I am looking something simple that I wouldn't care much what the hosting service provides me.



(01-12-2021, 09:24 PM)John_Betong Wrote: @kadirilkimen,

This may be of interest:

I have a localhost CI4 installation using Ubuntu with apache2:

I made the following changes:

1. renamed  /var/www/ci4-stict.tk/public_html/index.php to index-001.php
2. modified  /var/www/ci4-stict.tk/public_html/.htaccess -> RewriteRule ^(.*)$ index-001.php/$1 [L]
3. browsed to http://localhost/ci4-strict.tk/public_html/index-001.php

Delighted to say: splash page and all linked web-pages worked fine Smile

Edit:
I forgot to mention that I already had the following set:
Code:
// file: ./app/Config/App.php

public $indexPage = ''; //'index.php';

Is public_html the root folder for the website? CI 4 files doesn't have index.php in root folder. How did you get an index.php file in the root folder?

If public_html is not the root folder and it is actually "public" folder of the CI4, then you should probably did a different configuration to do it and it is the problem for me.

If you already have an index.php in root folder, why do you need to rename it like index-001.php? I didn't understand the point.

Angel  Yep. I am not so good developer. Yet I am exist and I believe that there are a lot of people like me that uses CI 3. Because it really makes things easier.

I am really curious if my solution has a significant drawbacks. Or any other solution would work with any simple shared webhosting without require server configuration.


RE: index.php in the root folder? - John_Betong - 01-13-2021

@kadirilkimen,
> Is public_html the root folder for the website? CI 4 files doesn't have index.php in root folder. How did you get an index.php file in the root folder?

Yes public_html is mother online root folder whereas local host is my local root folder. The online directory structure is mirrored locally. I have a VPS and apache2 set to default to index.php.

Except for the “assets” folder and .htaccess file, everything else is above the root.

The documentation states that the index.php can be safely renamed and I tried it to see if it would work. The idea was also to see if it could be installed alongside an existing application without any conflicts. Only problem I see is the common .htaccess file.

I am not sure of your server setup but as long as the index.php points to the application folder and system folder and the folder paths are set correctly then the directories could be anywhere even on an external host.


RE: index.php in the root folder? - iRedds - 01-13-2021

The problem is that everything in DOCUMENT_ROOT becomes available from the browser. And any mistake can be very costly. 
That is why index.html was placed in all directories in CI3 and less. That is why in CI4 all code was moved from the public directory.

I don't see any problems with shared hosting. Shared hostings always give access to a directory higher than the public directory.

Yes, often the public directory is called public_html. This is not to be feared. You put all the code in the parent directory public_html, and the entry point from public to public_html.


RE: index.php in the root folder? - kadirilkimen - 01-13-2021

@iRedds
Thanks for the explanation.

It makes sense. I was thinking that .htaccess files already blocks the access. But since browsers can't access upper level of public_html, it is obviously far more secure. It wasn't clear before but now I understand the concept I think.

Well, in this case, my silly attempt still seems ok if you are willing to compromise security down to CI 3 level. Yet, since the goal is being up to date, it is better to follow the correct path. And yes, if a hosting doesn't allow me to access upper level of public_html, better to stay away. If i can access to the upper level, then there is no problem to setup CI4 Sleepy