-
Notifications
You must be signed in to change notification settings - Fork 1.9k
feat: customizable .env
directory path
#9631
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Branch |
cac517a
to
23c6881
Compare
rebased |
While changing the I hope this option won't be abused to store the file in insecure places. Because, before we could be quite sure, it would be changed only by people who know what they're doing. However, from the other side, this is not the first voice from the community to make things easier in this area, so I suppose this is acceptable. Let's see what others will say. We will need a changelog entry for this. I didn't see a dedicated page for |
I think we should add a guard where the |
How to do it? |
What do you mean by that exactly? From what I understand it, I would be concerned about the |
Isn't the web-accessible path the In the following file structure:
isn't the paths accessible |
I don't see any documentation updates or changelogs. If it looks unsafe, it's worth adding information about the consequences.
|
@paulbalandan What I meant is that in an ideal setup, the domain points directly to the But when serving the app from a subfolder (e.g. http://app.test/subA), the entire From that perspective, everything from |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The proper documentation should be enough to warn users about the risks. I was looking at the user guide, and I believe this would be a good place for this: https://github.com/codeigniter4/CodeIgniter4/blob/develop/user_guide_src/source/general/managing_apps.rst
We can add a section dedicated to .env
at the bottom.
Changing the Location of the .env File
======================================
If necessary, you can change the location of the ``.env`` file by adjusting the ``$envDirectory``
property in ``app/Config/Paths.php``.
By default, the framework loads environment settings from a ``.env`` file located one level above
the ``app/`` directory (in the ``ROOTPATH``). This is a safe location when your domain is correctly
pointed to the ``public/`` directory, as recommended.
In practice, however, some applications are served from a subdirectory (e.g., ``http://example.com/myapp``)
rather than from the main domain. In such cases, placing the ``.env`` file within the ``ROOTPATH`` may expose
sensitive configuration if ``.htaccess`` or other protections are misconfigured.
To avoid this risk in such setups, it is recommended to ensure the ``.env`` file is located outside any
web-accessible directories.
.. warning::
If you change the location of the ``.env`` file, make absolutely sure it is not publicly accessible.
Exposure of this file could lead to compromised credentials and access to critical services, such as your
database, mail server, or third-party APIs.
d1aae1d
to
fb4e411
Compare
LGTM - we would need a changelog entry here: https://github.com/codeigniter4/CodeIgniter4/blob/4.7/user_guide_src/source/changelogs/v4.7.0.rst#enhancements |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some grammatical improvements with help from Github Copilot.
378a55c
to
58a0f80
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@totoprayogo1916 You can rebase one more time, to resolve Rector issues.
…to envDirectory Co-authored-by: Michal Sniatala <[email protected]>
Co-authored-by: Michal Sniatala <[email protected]>
Co-authored-by: Michal Sniatala <[email protected]>
4f91f35
to
69c5e4c
Compare
Co-authored-by: John Paul E. Balandan, CPA <[email protected]> Co-authored-by: Michal Sniatala <[email protected]> Co-authored-by: ddevsr <[email protected]>
69c5e4c
to
a601c2c
Compare
.env
directory path
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@totoprayogo1916 Sorry, I missed that, but we still need a changelog entry here: https://github.com/codeigniter4/CodeIgniter4/blob/4.7/user_guide_src/source/changelogs/v4.7.0.rst (preferably under the "Changes" section).
Maybe something similar to this:
- **Paths:** Added support for changing the location of the ``.env`` file via the ``Paths::$envDirectory`` property.
…e via Paths::$envDirectory property
Thank you @totoprayogo1916 |
Description
This PR restores the ability to set a custom .env file path, which was no longer possible after #8604 due to hardcoded handling in Boot.php.
Checklist: