craftcms / nitro

Speedy local dev environment for @craftcms.
https://getnitro.sh
MIT License
178 stars 24 forks source link

Craft 2: Calling console/yiic fails when using environment variables for db.php #312

Closed jamesmacwhite closed 3 years ago

jamesmacwhite commented 3 years ago

Description

This is a probably a bit of unique case, but for Craft 2 calling console/yiic under Nitro doesn't work, as it cannot connect to the database. I am using environment variables in the config/db.php but I don't believe the environment variables are available to the console request, as all the db parameters are blank. If I hard code this in the db.php it works:

'console' => [
   'server' => 'mysql-5.6-3307.database.nitro',
   'database' => 'database_name',
   'user' => 'nitro',
  'password' => 'nitro'
]

The environment variables do work for web requests however.

Is there anything that can be done, other than hard coding?

jasonmccallister commented 3 years ago

@jamesmacwhite maybe its worth looking at the code where Craft calls dotenv and adding it to the console file that loads PHP? Its been a really long time since I looked at Craft 2 but I will try to dig up an installation and ask someone on the team if they have the same issue.

jamesmacwhite commented 3 years ago

@jasonmccallister Ah, having a minor brain failure. Yes, I can just include the vendor and DotEnv load in my console/yiic before it's called. I assume previously the env vars have been available without this, but because of the Docker container being split, the env vars aren't set in the PHP container.

Don't worry, I think I have a fix, thanks!