Welcome Guest, Not a member yet? Register   Sign In
CI4 - Installation Location FOLDER example
#1

(This post was last modified: 08-19-2020, 01:15 PM by jinbatsu.)

I'm seeing so many people did not understand what public folder means.

Default Folder Structure from CI4
  • /app/
  • /public/
  • /system/
  • /writeable/
  • /.env
Localhost Development
What we should implement for localhost such as xampp, example in Windows, location in D:/xampp
And we want keep multi folder for our project, and we do not want to change httpd.conf everytime we switch the project what we work, specially if those project are linked on each project.

So, what we want to setup is like this, we should use the same folder name, so then we do not confuse by our self:
  • /xampp/htdocs/project1/ <-- this is public folder (copy only the files from public/* CI4)
  • /xampp/htdocs/project2/
  • /xampp/projects/project1/ <-- copy the rest including the folder name, like.: app/, system/, writeable/
  • /xampp/projects/project2/
To make it work, edit /xampp/htdocs/project1/index.php
From this
PHP Code:
// Path to the front controller (this file)
define('FCPATH'__DIR__ DIRECTORY_SEPARATOR);

// Location of the Paths config file.
// This is the line that might need to be changed, depending on your folder structure.
$pathsPath realpath(FCPATH '../app/Config/Paths.php');
// ^^^ Change this if you move your application folder 
To:
PHP Code:
// Path to the front controller (this file)
define('FCPATH'__DIR__ DIRECTORY_SEPARATOR);

// Location of the Paths config file.
// This is the line that might need to be changed, depending on your folder structure.
$pathsPath realpath(FCPATH '../../project1/app/Config/Paths.php');
// ^^^ Change this if you move your application folder 
That's it.

For using MAMP or the like, then we can point folder with additional public folder (just like for webhosting in below).

For webhosting (shared, vps, etc) for production:
Folder usally like this: /home/username/public_html/
So, we should put like this:
  • /home/username/public_html/index.php, .htaccess, favicon.ico
  • /home/username/public_html/assets/* (any other public js, images, css files)
  • /home/username/project1/app/
  • /home/username/project1/system/
  • /home/username/project1/system//writeable/
For subdomain, because our modern panel can specify folder document root, we can actually create public folder, so that all project is in one folder structure, like example:
Normally like this:
Not Good: app1.example.com => point to => /home/username/app1.example.com/
Instead we use additional public folder:
Good: app1.example.com => point to => /home/username/app1.example.com/public/

EDIT: it is also covered in the thread: https://forum.codeigniter.com/thread-76777.html

That's it, hope it clear.
Reply
#2

Hi.
In my host, there's the root directory in which I'm not allowed to upload files. It contains a htdocs repertory (the "public" folder) in which I'm supposed to put the files of my site ... Is there a solution to make a secure installation ?

Thanks.
Reply
#3

(This post was last modified: 08-20-2020, 04:01 PM by jinbatsu.)

(08-20-2020, 08:00 AM)Chris78 Wrote: In my host, there's the root directory in which I'm not allowed to upload files.

We should actually not touching anything outside from our username folder, including /root, /etc, /var,...
So, example our folders from hosting provider, my username is jinbatsu, so usually look like this:
/home/jinbatsu/public_html/
/home/jinbatsu/log/
/home/jinbatsu/mail/
/home/jinbatsu/temp/
...

So, we create new folder for our project CI4 files, example we name it the folder as project1.
/home/jinbatsu/project1/app
/home/jinbatsu/project1/system
/home/jinbatsu/project1/writeable

And public/* files from our CI4 we put to:
/home/jinbatsu/public_html/*

That's it. That's how we make our app and system outside from public_html (which is our default DOCROOT from hosting provider).
Reply
#4

Thanks for your reply.
Problem is that I don't have any username folder ... Don't know how the host works, with cpanel, I go directly to a folder that contains htdocs (like public_html for you). Impossible for me to put anything outside this htdocs folder !
Reply
#5

(08-20-2020, 08:00 AM)Chris78 Wrote: Hi.
In my host, there's the root directory in which I'm not allowed to upload files. It contains a htdocs repertory (the "public" folder) in which I'm supposed to put the files of my site ... Is there a solution to make a secure installation ?

Thanks.

Did you try uploading them using FTP? I'm on shared hosting with public_html

And I can FTP my  whole project to the root.

If you have CPanel setup an FTP user and try it.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#6

Yes, I tried with FTP and I get "permission denied" either when I try to upload a file or to create a drectory ...
Reply
#7

Can you upload a php script like this name it test.php, and see what printed out in browser?

PHP Code:
<?php
echo 'Here my folder: ' dirname(__FILE__).DIRECTORY_SEPARATOR

My result example is:
Here my folder: /home/xxx/public_html/

And what panel it is in your hosting? cPanel/Directadmin/Plesk or ?
Reply




Theme © iAndrew 2016 - Forum software by © MyBB