• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Multiple instances of CI4 and removal of public/index.php/ from url

#1
I am working on a project that will solve multiple problems but a user may potentially use more than one of these solutions.

So I have an instance of CI4 handling users (logins, passwords etc) with its own database.

I have another instance of CI4 implementing a solution to the first problem with its own database.

I will soon be using another instance CI4 to solve another problem that I have already identified.

But no user should use any of these solutions without going through the CI4 instance that authenticates users among other things basic

.
.
.

When I was using CI3, there was no problem. The trouble is that CI4 has introduced the 'public' directory which is now my headache.

Whenever an instance X of CI4 is the one active I now have my URL as http://localhost/InstanceXofCI4/public/view. The 'index.php' is out of the way but I am stuck with 'public' directory.

Is it possible to hide the 'public' directory without changing the default directory structure?
Reply

#2
Your document root mapped path should point to the /public folder, not for root CI4 project folder.

E.g.: DocumentRoot /home/user/www/ci4folder/public


(03-17-2020, 05:21 PM)owino Wrote: I am working on a project that will solve multiple problems but a user may potentially use more than one of these solutions.

So I have an instance of CI4 handling users (logins, passwords etc) with its own database.

I have another instance of CI4 implementing a solution to the first problem with its own database.

I will soon be using another instance CI4 to solve another problem that I have already identified.

But no user should use any of these solutions without going through the CI4 instance that authenticates users among other things basic

.
.
.

When I was using CI3, there was no problem. The trouble is that CI4 has introduced the 'public' directory which is now my headache.

Whenever an instance X of CI4 is the one active I now have my URL as http://localhost/InstanceXofCI4/public/view. The 'index.php' is out of the way but I am stuck with 'public' directory.

Is it possible to hide the 'public' directory without changing the default directory structure?
Reply

#3
You can change the root directory from your server.
Example : before www/dirname/ change to www/dirname/public/

Or you can place your CI asset in another directory and put the content of public in your root then change the config of index.php

Example : www/user/public_html/index.php <- this is public dir
Then I point the codeigniter to www/user/_codeigniter/

(03-17-2020, 05:21 PM)owino Wrote: I am working on a project that will solve multiple problems but a user may potentially use more than one of these solutions.

So I have an instance of CI4 handling users (logins, passwords etc) with its own database.

I have another instance of CI4 implementing a solution to the first problem with its own database.

I will soon be using another instance CI4 to solve another problem that I have already identified.

But no user should use any of these solutions without going through the CI4 instance that authenticates users among other things basic

.
.
.

When I was using CI3, there was no problem. The trouble is that CI4 has introduced the 'public' directory which is now my headache.

Whenever an instance X of CI4 is the one active I now have my URL as http://localhost/InstanceXofCI4/public/view. The 'index.php' is out of the way but I am stuck with 'public' directory.

Is it possible to hide the 'public' directory without changing the default directory structure?

If you use shared hosting, or cant point the root directory. You can choose my 2nd option. If you have root access you just need to change the root directory
Hi! I am Jamil
Reply

#4
Yes, you can remove the public/ directory completely, but this will introduce security issues since all of the CodeIgniter files will be accessible from the web.
You can read on how you can set up multiple applications using a single instance of CI4, so that your directory structure could be like

system...
vendor...
writable...
public_html
     app1
     app2

Otherwise, if you want all files in your in the same directory as the index, you can create an index.php file in the root of your CI instance then paste the following code

PHP Code:
<?php

// Valid PHP Version?
$minPHPVersion '7.2';
if (
phpversion() < $minPHPVersion)
{
    die(
"Your PHP version must be {$minPHPVersion} or higher to run CodeIgniter. Current version: " phpversion());
}
unset(
$minPHPVersion);

// 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 FCPATH 'app/Config/Paths.php';
// ^^^ Change this if you move your application folder

/*
 *---------------------------------------------------------------
 * BOOTSTRAP THE APPLICATION
 *---------------------------------------------------------------
 * This process sets up the path constants, loads and registers
 * our autoloader, along with Composer's, loads our constants
 * and fires up an environment-specific bootstrapping.
 */

// Ensure the current directory is pointing to the front controller's directory
chdir(__DIR__);

// Load our paths config file
require $pathsPath;
$paths = new Config\Paths();

// Location of the framework bootstrap file.
$app = require rtrim($paths->systemDirectory'/ ') . '/bootstrap.php';

/*
 *---------------------------------------------------------------
 * LAUNCH THE APPLICATION
 *---------------------------------------------------------------
 * Now that everything is setup, it's time to actually fire
 * up the engines and make this app do its thang.
 */
$app->run(); 
Reply

#5
(03-18-2020, 03:54 AM)mjamilasfihani Wrote: You can change the root directory from your server.
Example : before www/dirname/ change to www/dirname/public/

Or you can place your CI asset in another directory and put the content of public in your root then change the config of index.php

Example : www/user/public_html/index.php <- this is public dir
Then I point the codeigniter to www/user/_codeigniter/


Sorry, I should have stated how my folder structure looks. My document root according to the apache2 server is /var/www/html. In this root directory is where I have copies of instances of CI4. So far I have two copies, the one that authenticates users and one that offers a solution to the first problem. Within the root also is an index.php file whose job is simply to direct visitors to the authenticating instance.Once a user has been authenticated, they are directed to an instance that offers a solution.So the sturcture looks like this
/var/www/html/
    index.php
    CI4auth/
    CI4soln1/
    CI4soln2/

So as I stated, whenever an instance of CI4 is active I now have my URLs as
    http://localhost/CI4auth/public/view
    http://localhost/CI4soln1/public/view
    http://localhost/CI4soln2/public/view

etc.

My wish is to hide the public directory so that I have
     http://localhost/CI4auth/view
    http://localhost/CI4soln1/view
    http://localhost/CI4soln2/view



(03-17-2020, 05:21 PM)owino Wrote: I am working on a project that will solve multiple problems but a user may potentially use more than one of these solutions.

So I have an instance of CI4 handling users (logins, passwords etc) with its own database.

I have another instance of CI4 implementing a solution to the first problem with its own database.

I will soon be using another instance CI4 to solve another problem that I have already identified.

But no user should use any of these solutions without going through the CI4 instance that authenticates users among other things basic

.
.
.

When I was using CI3, there was no problem. The trouble is that CI4 has introduced the 'public' directory which is now my headache.

Whenever an instance X of CI4 is the one active I now have my URL as http://localhost/InstanceXofCI4/public/view. The 'index.php' is out of the way but I am stuck with 'public' directory.

Is it possible to hide the 'public' directory without changing the default directory structure?

If you use shared hosting, or cant point the root directory. You can choose my 2nd option. If you have root access you just need to change the root directory

Sorry, I should have stated how my folder structure looks. My document root according to the apache2 server is /var/www/html. In this root directory is where I have copies of instances of CI4. So far I have two copies, the one that authenticates users and one that offers a solution to the first problem. Within the root also is an index.php file whose job is simply to direct visitors to the authenticating instance.Once a user has been authenticated, they are directed to an instance that offers a solution.So the sturcture looks like this
/var/www/html/
index.php
CI4auth/
CI4soln1/
CI4soln2/

So as I stated, whenever an instance of CI4 is active I now have my URLs as
http://localhost/CI4auth/public/view
http://localhost/CI4soln1/public/view
http://localhost/CI4soln2/public/view

etc.

My wish is to hide the public directory so that I have
http://localhost/CI4auth/view
http://localhost/CI4soln1/view
http://localhost/CI4soln2/view
Reply

#6
You can do that with uri routing. It will reduce your time for rewriting again and again, point your root directory first then you can do some experiment with that

Happy code Smile
Hi! I am Jamil
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.