Welcome Guest, Not a member yet? Register   Sign In
Multi applications with same app folder but different configurations
#2

Maybe I found a solution, I just want to understand two things.
I've slightly modified the structure like this, but just for my convenience

app/
website1/
    .env
    builds
    phpunit.xml.dist
    preload.php
    public/
    spark
    tests/
    writable/
website2/
    .env
    builds
    phpunit.xml.dist
    preload.php
    public/
    spark
    tests/
    writable/
vendor/
    autoload.php
    codeigniter4/framework/
composer.json
composer.lock


To solve the $baseURL problem for the different applications I added these 2 lines in Config/Constants.php:


PHP Code:
$base_url = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off' 'https://' $_SERVER['HTTP_HOST'] : 'http://' $_SERVER['HTTP_HOST'];

defined('BASE_URL_DYNAMIC') || define('BASE_URL_DYNAMIC'$base_url); 


And then to Config/App.php

PHP Code:
public $baseURL BASE_URL_DYNAMIC


Now, for variables that differ between application and application I opted to use the .env file.

In order to use one .env file for each application (see structure), I had to change a line on public/index.php and spark

In index.php I created a constant to get the application folder

PHP Code:
defined('WEBSITE_PATH') || define('WEBSITE_PATH'basename(realpath(__DIR__ DIRECTORY_SEPARATOR '..'))); 


I then use it both in index.php and in spark to load the .env file dedicated to each individual application

I changed this

PHP Code:
(new CodeIgniter\Config\DotEnv(ROOTPATH))->load(); 


to this

PHP Code:
(new CodeIgniter\Config\DotEnv(ROOTPATH DIRECTORY_SEPARATOR WEBSITE_PATH))->load(); 


At this point having an .env file for each application, the problem of the database name no longer exists and also for any variables dedicated to each application

For example, having the ROOTPATH constant pointing to the root folder which contains app, vendor, website1 and website2, while the other files (which are normally also found in the root), are instead contained in the various folders of the different applications, this could it cause problems in the functioning of anything?

Will preload.php, builds and other files included in the document roots (website1 and website2) continue to do their job in this location?

Am I doing something right or am I on the wrong track?
Reply


Messages In This Thread
RE: Multi applications with same app folder but different configurations - by serialkiller - 11-18-2022, 03:42 AM



Theme © iAndrew 2016 - Forum software by © MyBB