Skip to content
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

Fatal error: Unable to read the .env environment file if project is installed with a public-directory like docroot/ #50

Open
Moongazer opened this issue Sep 18, 2023 · 1 comment

Comments

@Moongazer
Copy link

Moongazer commented Sep 18, 2023

Using mautic/recommended-project to install Mautic 4 with Composer using a public-directory like docroot/ works well.

Doing the same for Mautic 5 fails, because the bootstrap is looking for a .env file inside the public direcotry docroot/, instead of the project-root where the mautic:install command creates it:

Fatal error: Uncaught Symfony\Component\Dotenv\Exception\PathException: Unable to read the "/var/www/html/docroot/app/../.env" environment file. in /var/www/html/vendor/symfony/dotenv/Dotenv.php:567 Stack trace: #0 /var/www/html/vendor/symfony/dotenv/Dotenv.php(114): Symfony\Component\Dotenv\Dotenv->doLoad(false, Array) #1 /var/www/html/docroot/app/config/bootstrap.php(17): Symfony\Component\Dotenv\Dotenv->loadEnv('/var/www/html/d...', NULL, 'prod') #2 /var/www/html/docroot/index.php(9): require('/var/www/html/d...') #3 {main} thrown in /var/www/html/vendor/symfony/dotenv/Dotenv.php on line 567

This is the generated folder structure (shortened):

/mautic-project
  bin/
  docroot/
    app/
    media/                // in local.php config we set 'upload_dir' => '%kernel.project_dir%/../media/files' etc...
    plugins/
    themes/
    translations/
    index.php
  var/                    // in local.php config we set 'cache_path' => '%kernel.project_dir%/../../var/cache' etc...
  vendor/
  .env                    // generated by mautic:install command
  composer.json

How is it possible to configure the application to look inside the root for the .env file? Because it holds sensitive information, it is not recommend to have it inside the public directory.

Edit:
One sub-optimal workaround would be to patch the file docroot/app/config/bootstrap.php adding ../ to the path (using composer-patches):

(new Dotenv())->loadEnv(dirname(__DIR__).'/../../.env', null, 'prod');
@mollux
Copy link
Collaborator

mollux commented Jan 18, 2024

@Moongazer I just tried to reproduce this with the last release (5.0.2), and it works as expected

composer create-project mautic/recommended-project:^5.0 some-dir --no-interaction
<< output >>
cd some-dir
php ./bin/console mautic:install http://default <<all extra needed paramters>>

php ./bin/console mautic:install http://default 
Mautic Install
==============

Parsing options and arguments...
0 - Checking installation requirements...
Missing optional settings:
  - [0] It is recommended to secure your installation with an SSL certificate (https). Starting February 2020 Google Chrome will stop sending third-party cookies in cross-site requests unless the cookies are secure. Tracking will stop working for Mautic instances running on HTTP. Use HTTPS.
  - [1] The <strong>memory_limit</strong> setting in your PHP configuration is lower than the suggested minimum limit of %min_memory_limit%. Mautic can have performance issues with large datasets without sufficient memory.
  - [2] Configure <code>zend.assertions = -1</code> in php.ini for production environments for faster and more stable execution.
Ready to Install!
1 - Creating database...
1.1 - Creating schema...
1.2 - Loading fixtures...
2 - Creating admin user...
3 - Final steps...

================
Install complete
================

the contents of the config/local.php contains only the following keys:

	'db_driver' => 'pdo_mysql',
	'db_host' => 'localhost',
	'db_table_prefix' => null,
	'db_port' => '3306',
	'db_name' => 'test_db',
	'db_user' => 'root',
	'db_password' => 'toor',
	'db_backup_tables' => 0,
	'db_backup_prefix' => 'bak_',

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants