Welcome Guest, Not a member yet? Register   Sign In
Location and Name of CI v4 .env File
#1

Hi Everyone,

I am diving into CI v4 after using CI v3 and v2.  Learning and liking it the more I use it.  Keep up the great work CI dev team.

I am using XAMPP with virtual hosts for local development.  I have the CI public folder in the XAMPP htdocs directory and both the application and system directories outside the public directory, and renamed to suit the project.  Configuration paths are all set and sites work.

If CI expects .env to be named as such, and in the same directory as the application and system folders, I can only have one .env file 'active' at a time while developing on localhost.

To be able to develop across multiple projects at the same, the only way I see of referencing the .env file is modifying its name and replacing / extending the System's Config\DotEnv class and passing a new name in the constructor.

PHP Code:
public function __construct(string $pathstring $file '.env_project_name')
{
 
$this->path rtrim($pathDIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR $file;


Is the best way to go about it?
Reply
#2

I prefer to ONLY have common Local and Remote .env settings and use the following to test and modify app/config/ files:

PHP Code:
<?php // index.php
defined('LOCALHOST')
?:
define('LOCALHOST''localhost'===$_SERVER['SERVER_NAME']);

// app/Config/Database.php
public $default = [
'DSN'      => '',
'hostname' => 'localhost',
'username' => LOCALHOST 'localuser'     'onlineuser',
'password' => LOCALHOST 'localpassword' 'onlinepassword',
'database' => 'mydbname',
'DBDriver' => 'MySQLi'
... 
Reply
#3

(This post was last modified: 11-11-2020, 07:24 AM by captain-sensible.)

Not sure if your on Linux xampp for Windows used to be called WAMP  but i have a few web dev all in the same hosting space.

Currently I have in /var/www/htdocs/  one wordpress and the rest CI4:

Code:
├── GBYS
├── andrinaDesStudio
├── andrinaPerfectBeauty
├── appstarter
├── basic
├── ginabrookes
├── index.php
└── wp

everything above is a directory and each has its own config with no clash. This is what it looks like inside one dev:


Code:
basic
├── README.md
├── app
├── builds
├── composer.json
├── composer.lock
├── env
├── license.txt
├── phpunit.xml.dist
├── public
├── spark
├── tests
├── vendor
└── writable


the trick is to make use of virtualhost  :

Code:
<VirtualHost 127.0.0.8:80>
ServerName wp.com
ServerAlias www.wp.com
DocumentRoot "/var/www/htdocs/wp"
<Directory "/var/www/htdocs/wp">
Order allow,deny
Allow from All
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
<VirtualHost 127.0.0.2:80>
ErrorLog "/var/log/httpd/girls_be_yourself.org-error_log"
<Directory "/var/www/htdocs/GBYS/public">
Order allow,deny
Allow from All
AllowOverride All
Require all granted
</Directory>
ServerName CI.org
DocumentRoot "/var/www/htdocs/GBYS/public"
ServerAlias www.GBYS.org

</VirtualHost>


FOr the Wordpress site i stipulate I can access site via address bar in web browser using 127.0.0.8 and for one of the CI4 GBYS i access in browser using 127.0.0.2  . Also i point webserver to listen to requests from the web root of the directory called "wp" whereas via virtual host config i tell it to listen at GPWS/public .

Every web dev has its own config , with no clash .


if you want to use domain in web address you can use /etc/hosts such as:

127.0.0.8 <some domain alias>
127.0.0.2 <some other>
Reply
#4

Thanks for your replies.  I am on Windows.

@captain-sensible - I like the set-up for your localhost dev.  Moving that same directory structure, (e.g., what is inside the 'basic' directory), to a (production) server keeps the application and system directories out of the public folder, and each, as you say, has its own .env file, cool!

Time to restructure when I can  Smile
Reply
#5

(11-12-2020, 03:54 AM)Mr Lister Wrote: Thanks for your replies.  I am on Windows.

@captain-sensible - I like the set-up for your localhost dev.  Moving that same directory structure, (e.g., what is inside the 'basic' directory), to a (production) server keeps the application and system directories out of the public folder, and each, as you say, has its own .env file, cool!

Time to restructure when I can  Smile
with subdomain i use similar trick to point listening of requests to public and so there is no change from local setup. Where you can't have subdomain you put everything inside public to inside hosting root ,probably names public_html everything else you pack into one directory and then change
Code:
$pathsPath = realpath(FCPATH . '../app/Config/Paths.php');

in index
Reply




Theme © iAndrew 2016 - Forum software by © MyBB