Comments (2)
Seems to work here for me, can you try again?
I added it in my .env.local
from forkcms.
The env vars (e.g. db credentials) are set in the runtime of the container but not in the .env
files. It works perfectly in general in the CMS, but some queries that SpoonDB executes in the Kernel bootup time will fail silently (try catch wrapped around it on Settings > Modules page).
Steps to reproduce:
- Clone a fresh repo:
git clone [email protected]:forkcms/forkcms.git fork-cms-issue-3322
cd fork-cms-issue-3322
- Make some changes to the
docker-compose.yml
file to avoid some errors on startup.
services:
app:
build:
context: .
cache_from: [ghcr.io/forkcms/forkcms:latest]
working_dir: /var/www/html
ports:
- "80:80"
- "443:443"
depends_on:
- db
- env_file: ./var/docker/.env
+ environment:
+ - DB_HOST=db
+ - DB_NAME=forkcms
+ - DB_USER=forkcms
+ - DB_PASSWORD=forkcms
volumes:
- - .:/var/www/html:cached
+ #- .:/var/www/html:cached
- ./src/Frontend/Files:/var/www/html/src/Frontend/Files:cached
- fork-cms-var:/var/www/html/var
- Start docker-compose:
docker-compose build && docker-compose up -d
- Wait 5-10min to build the image :troll:
- Run
docker-compose exec app bash -c 'echo -e "FORK_ENV=dev\nFORK_DEBUG=1" > .env && composer install -o && chown -R www-data:www-data /var/www/html'
otherwise it will complain about a missing.env
in the root and throw errors (I should make a PR to make this more smooth😭 ). - Visit http://localhost/ and complete the installer. Use DB hostname "db" and dbname/username/password set to
forkcms
. - Once the installer is finished, and you can visit the website, use
docker-compose exec app bash
to step into the container and install vim:apt-get update && apt-get install -y vim
(or nano) vi app/config/parameters.yml
and switch it to these values:
database.host: '%env(DB_HOST)%'
database.name: '%env(DB_NAME)%'
database.user: '%env(DB_USER)%'
database.password: '%env(DB_PASSWORD)%'
- Run
printenv
to check that theseDB_HOST
,DB_NAME
,DB_USER
andDB_PASSWORD
values are correctly set. - Reload the page and login to the CMS
- Everything still works
👍 - Go to Settings > Modules --> all modules are installed? That's not correct.
- The issue is in
app/Kernel.php
ingetInstalledModules
. There's a bigtry/catch
around the SpoonDB querySELECT name FROM modules
. https://github.com/forkcms/forkcms/blob/master/app/Kernel.php#L166-L174 - Try to print the PDO connection string:
vi vendor/spoon/library/spoon/database/database.php
and go to line 164. Entervar_dump($dsn);
. Then go tovi app/Kernel.php
and on line 174 inside thecatch (SpoonDatabaseException $e)
place this:var_dump($e->getMessage());
. Now save and reload the page.
/var/www/html/vendor/spoon/library/spoon/database/database.php:165:string 'mysql:host=env_DB_HOST_e93a13b12f8a11b61d2543b705df8f47;dbname=env_DB_NAME_c7754016e01b949d9226a29c3748622b;user=env_DB_USER_5aa8d02d6f073b416daf37e3a31d75d6;password=env_DB_PASSWORD_61ae438821ee6d4b4669861c2986cc5c;port=3306;charset=utf8' (length=238)
/var/www/html/app/Kernel.php:174:string 'A database connection could not be established.' (length=47)
/var/www/html/vendor/spoon/library/spoon/database/database.php:165:string 'mysql:host=db;dbname=forkcms;user=forkcms;password=forkcms;port=3306;charset=utf8' (length=81)
So, somehow the env vars are not resolved in the SpoonDB PDO object when the Kernel.php is booting up. But we did not use a die()
statement in the SpoonDatabaseException... And we see the SpoonDB got initialized again, but this time with the correct credentials! Only shortly after the Kernel booted, the env vars are properly set in the database object?
from forkcms.
Related Issues (20)
- Use ServiceEntityRepository HOT 1
- Use ModuleExtra entity
- Remove Analytics Module HOT 1
- Pages - Improve performance of pages module HOT 1
- Pages - handle unlinked blocks
- Pages - preview url for home HOT 1
- Pages - rename HTML field HOT 1
- Core - addCSS and addJS
- Profiles module frontend, users need to login twice HOT 8
- Pages - Broken usertemplates HOT 2
- Send email from within ajax callback HOT 1
- GenerateUrl ajax call error HOT 3
- Formbuilder : Labels with special chars HOT 2
- Error 500 in 5.11 release. Missing autoload.php HOT 10
- Breadcrumbs: code "if loop last" removes delimiter in pure bootstrap HOT 4
- Can't add links to images in editor HOT 1
- Add toggles to MediaLibrary and disable default 'strip' functionality
- Locale - Only rows with the "label" type fields are exported, the rest are ignored HOT 1
- Fix htaccess redirect for URL's which contain "bin/" HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from forkcms.