<p>I'm trying to upgrade from 2.7.10 to Craft 3. I follow the <a href="https://docs.craftcms.com/v3/upgrade.html#performing-the-upgrade" rel="nofollow noreferrer">instructions/ docs</a> to the letter, go to <a href="https://###.com/admin" rel="nofollow noreferrer">https://###.com/admin</a> and am greeted with the above can't connect to database message. </p>

<p>So far, I have pretty much done everything to eliminate possibilities and the conclusion I have come to is that the <code>.env</code> file isn't being loaded. Obviously, I could well be wrong, but I tried a <code>die</code> <code>Hello World</code> on the <code>db.php</code> file and it worked. I put the database details directly into the <code>db.php</code> file and it worked, albeit took me to the current install rather than the upgrade page. I even created a new database (just to try it) and still got the same error.</p>

<p>The db file looks like this:</p>

<pre><code>&lt;?php
/**
 * Database Configuration
 *
 * All of your system's database connection settings go in here. You can see a
 * list of the available settings in vendor/craftcms/cms/src/config/DbConfig.php.
 *
 * @see craft\config\DbConfig
 */

return [
    'driver' =&gt; getenv('DB_DRIVER'),
    'server' =&gt; getenv('DB_SERVER'),
    'user' =&gt; getenv('DB_USER'),
    'password' =&gt; getenv('DB_PASSWORD'),
    'database' =&gt; getenv('DB_DATABASE'),
    'schema' =&gt; getenv('DB_SCHEMA'),
    'tablePrefix' =&gt; getenv('DB_TABLE_PREFIX'),
    'port' =&gt; getenv('DB_PORT')
];
</code></pre>

<p>And the env file: </p>

<pre><code># The environment Craft is currently running in ('dev', 'staging', 'production', etc.)
ENVIRONMENT="dev"

# The secure key Craft will use for hashing and encrypting data
SECURITY_KEY="*************"

# The database driver that will be used ('mysql' or 'pgsql')
DB_DRIVER="mysql"

# The database server name or IP address (usually this is 'localhost' or '127.0.0.1')
DB_SERVER="localhost"

# The database username to connect with
DB_USER="####"

# The database password to connect with
DB_PASSWORD="**************"

# The name of the database to select
DB_DATABASE="####"

# The database schema that will be used (PostgreSQL only)
DB_SCHEMA="public"

# The prefix that should be added to generated table names (only necessary if multiple things are sharing the same database)
DB_TABLE_PREFIX="craft"

# The port to connect to the database with. Will default to 5432 for PostgreSQL and 3306 for MySQL.
DB_PORT="3306"
</code></pre>

<p>Can anyone shed anymore light on how I can resolve this please? I am new to this so please be gentle and let me know if you need more info. 
Thanks. </p>

CC BY-SA 4.0
2019-09-17T09:08:09.757Z
Is this error on the command line, or on front-end?
dmatthams
CC BY-SA 4.0
2019-09-17T09:25:00.990Z
Front-end.  I'm not using Composer or anything if that helps.
deebie77
CC BY-SA 4.0
2019-09-17T09:30:39.860Z
It's strange that it works directly from the db.php. What's your local server setup, is it MAMP or something else? It's a long shot (I don't think it's this) but have you tried 127.0.0.1 as your server setting?
dmatthams
CC BY-SA 4.0
2019-09-17T09:36:24.110Z
I'm not using MAMP, I have uploaded it via FTP.  I also tested it on another server (for a different website) and go the same message, but, again, when I put the details directly into the db.php it worked.  I did try changing the server to 127.0.0.1 but got the same issue.
deebie77
CC BY-SA 4.0
2019-09-17T09:47:14.217Z
Hopefully, someone else may be able to help, but I think my next step would be to try a fresh install of Craft 3 in the same environment to see if it's an issue with your install or the environment.
dmatthams
CC BY-SA 4.0
2019-09-17T09:49:38.230Z
OK, thanks. To be honest, I've tried fresh installing twice and I'm still getting the same error. Thanks again.
deebie77
CC BY-SA 4.0
2019-09-17T09:52:09.457Z
In that case, I would say something is up with your environment, have you tried the craft server checker? https://github.com/craftcms/server-check
dmatthams
CC BY-SA 4.0
2019-09-17T09:54:59.410Z
I haven't.  I'll give it a go.  Thanks for this.
deebie77
CC BY-SA 4.0
2019-09-17T15:13:00.027Z
The server checker all came back fine, except the ini_sets, but this is because the server uses PHP-FPM rather than standard PHP. However, I'm not sure this should make a difference as Craft2 is installed without issue, although I could be wrong.
deebie77
CC BY-SA 4.0
2019-09-18T10:23:39.267Z
Have you checked out your server php logs to see if there's anything there? Also worth checking Craft's web.log, but have a feeling this may not show much. Failing that I would probably get in touch with Craft support.
dmatthams
CC BY-SA 4.0
2019-09-18T11:06:30.677Z
Thanks. Yeah, I'm in touch with Brad now and I think it is agreed that the values from the .env file aren't being loaded. Thanks for your help :)
deebie77
CC BY-SA 4.0
2020-01-24T06:54:49.497Z
@deebie77 did you able to solve this issue?
Sameera Thilakasiri
<craft3><database><config><php>
Craft can’t connect to the database with the credentials in craft/config/db.php
# Craft can’t connect to the database with the credentials in craft/config/db.php

(Asked by: username_0 on 2019-09-17)

I'm trying to upgrade from 2.7.10 to Craft 3. I follow the instructions/ docs to the letter, go to https://###.com/admin and am greeted with the above can't connect to database message. 
So far, I have pretty much done everything to eliminate possibilities and the conclusion I have come to is that the .env file isn't being loaded. Obviously, I could well be wrong, but I tried a die Hello World on the db.php file and it worked. I put the database details directly into the db.php file and it worked, albeit took me to the current install rather than the upgrade page. I even created a new database (just to try it) and still got the same error.
The db file looks like this:
 getenv('DB_DRIVER'),
    'server' => getenv('DB_SERVER'),
    'user' => getenv('DB_USER'),
    'password' => getenv('DB_PASSWORD'),
    'database' => getenv('DB_DATABASE'),
    'schema' => getenv('DB_SCHEMA'),
    'tablePrefix' => getenv('DB_TABLE_PREFIX'),
    'port' => getenv('DB_PORT')
];

And the env file: 
# The environment Craft is currently running in ('dev', 'staging', 'production', etc.)
ENVIRONMENT="dev"

# The secure key Craft will use for hashing and encrypting data
SECURITY_KEY="*************"

# The database driver that will be used ('mysql' or 'pgsql')
DB_DRIVER="mysql"

# The database server name or IP address (usually this is 'localhost' or '127.0.0.1')
DB_SERVER="localhost"

# The database username to connect with
DB_USER="####"

# The database password to connect with
DB_PASSWORD="**************"

# The name of the database to select
DB_DATABASE="####"

# The database schema that will be used (PostgreSQL only)
DB_SCHEMA="public"

# The prefix that should be added to generated table names (only necessary if multiple things are sharing the same database)
DB_TABLE_PREFIX="craft"

# The port to connect to the database with. Will default to 5432 for PostgreSQL and 3306 for MySQL.
DB_PORT="3306"

Can anyone shed anymore light on how I can resolve this please? I am new to this so please be gentle and let me know if you need more info. 
Thanks.

**Tags:** craft3, database, config, php
> **Comments:**
> **username_1**: Is this error on the command line, or on front-end?  
> **username_0**: Front-end.  I'm not using Composer or anything if that helps.  
> **username_1**: It's strange that it works directly from the db.php. What's your local server setup, is it MAMP or something else? It's a long shot (I don't think it's this) but have you tried 127.0.0.1 as your server setting?  
> **username_0**: I'm not using MAMP, I have uploaded it via FTP.  I also tested it on another server (for a different website) and go the same message, but, again, when I put the details directly into the db.php it worked.  I did try changing the server to 127.0.0.1 but got the same issue.  
> **username_1**: Hopefully, someone else may be able to help, but I think my next step would be to try a fresh install of Craft 3 in the same environment to see if it's an issue with your install or the environment.  
> **username_0**: OK, thanks. To be honest, I've tried fresh installing twice and I'm still getting the same error. Thanks again.  
> **username_1**: In that case, I would say something is up with your environment, have you tried the craft server checker? https://github.com/craftcms/server-check  
> **username_0**: I haven't.  I'll give it a go.  Thanks for this.  
> **username_0**: The server checker all came back fine, except the ini_sets, but this is because the server uses PHP-FPM rather than standard PHP. However, I'm not sure this should make a difference as Craft2 is installed without issue, although I could be wrong.  
> **username_1**: Have you checked out your server php logs to see if there's anything there? Also worth checking Craft's web.log, but have a feeling this may not show much. Failing that I would probably get in touch with Craft support.  
> **username_0**: Thanks. Yeah, I'm in touch with Brad now and I think it is agreed that the values from the .env file aren't being loaded. Thanks for your help :)  
> **username_2**: @deebie77 did you able to solve this issue?  

---

## 0 answers

