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');
Using
mautic/recommended-projectto install Mautic 4 with Composer using a public-directory likedocroot/works well.Doing the same for Mautic 5 fails, because the bootstrap is looking for a
.envfile inside the public direcotrydocroot/, instead of the project-root where themautic:installcommand creates it:This is the generated folder structure (shortened):
How is it possible to configure the application to look inside the root for the
.envfile? 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.phpadding../to the path (using composer-patches):