Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ajsmith_codes's avatar

Access denied for user after deployment.

Can't seem to find the answer to this one in the forums or by Googling...

After deploying to a live server, I can't seem to login to my app. I tested the db connection with a script and it was working. So, I thought maybe it's my username/password. However, when I changed the password in phpmyadmin, it still doesn't work.

Here is the error:

```SQLSTATE[HY000] [1045] Access denied for user 'hollys7_inexhaus'@'localhost' (using password: YES) (SQL: select * from users where email = [email protected] limit 1)

SQLSTATE[HY000] [1045] Access denied for user 'hollys7_inexhaus'@'localhost' (using password: YES)
0 likes
29 replies
mvdnbrk's avatar

The error message gives you the answer. There is a connecting problem with your database: Access denied.

esorone's avatar

Hello,

What I normally do, is copy the hashed password from my dev environment, into the data base of the live environment. Just to make sure that that one is not the issue. If you still have an issue, maybe the user doesn’t have access to the database.

jlrdw's avatar

Sounds like your database credentials wasn't changed or setup for hosting. Not laravel but your MySQL credentials.

ajsmith_codes's avatar

@esorone I tried that and got the same error. However, if I test the db connection via a PHP script, it makes the connection.

Here's my .env:

DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=removed for security DB_USERNAME=removed for security DB_PASSWORD=removed for security

mvdnbrk's avatar

@ajsmith_codes Your test script probably don't use the same credentials as your test script. Check your mysql credentials in the .env file on the production server.

ajsmith_codes's avatar

@mvdnbrk They are the same credentials. When I say test script, I mean that I used this on the server:

```$database = "inexha5_hub";
```$username = 
```$password = 

```Create connection
```$conn = new mysqli($servername, $username, $password, $database);
```Check connection
```if ($conn->connect_error) {
   ```die("Connection failed: " . $conn->connect_error);
```}
  ```echo "Connected successfully";
esorone's avatar

Just a guess, but what happens if you change the 127.0.0.1 into localhost?

jlrdw's avatar

Clear your config cache after changes.

ajsmith_codes's avatar

Update:

I tried to run migrate from the command line and got the same connection error. I can't seem to figure out why I can get a connection via a PHP script with the same credentials as my .env file.

mvdnbrk's avatar

Your test script does not use the the values provided by your .env file. So that script won't help you out.

  • Remove the configuration cache file: php artisan config:clear
  • Maybe there is something altered in your database config file
  • are your sure the .env file exits in the correct place with the correct credentials
  • just another guess: is your .env value. Example APP_NAME=My Site (without quotes may give problems, APP_NAME="My Site"
ajsmith_codes's avatar

@mvdnbrk

I entered the same values into the .env file as I did the script, so they were the same. I think everyone is confused about that. I'm not talking about a local test file. I created the usual PHP test code that results in an answer when you run it. Does that make sense? You can see it here: http://inexhaustsystems.com/test.php

I tried to clear the cache. I checked the database config file:

    'mysql' => [
        'driver' => 'mysql',
        'url' => env('DATABASE_URL'),
        'host' => env('DB_HOST', '127.0.0.1'),
        'port' => env('DB_PORT', '3306'),
        'database' => env('DB_DATABASE', 'forge'),
        'username' => env('DB_USERNAME', 'forge'),
        'password' => env('DB_PASSWORD', ''),
        'unix_socket' => env('DB_SOCKET', ''),
        'charset' => 'utf8mb4',
        'collation' => 'utf8mb4_unicode_ci',
        'prefix' => '',
        'prefix_indexes' => true,
        'strict' => true,
        'engine' => null,
        'options' => extension_loaded('pdo_mysql') ? array_filter([
            PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
        ]) : [],
    ],

I do believe the .env file is in the correct spot, because when I change the values in it, it is showing up in the error.

No luck adding the quotation marks.

spyworld's avatar

127.0.1.1 is part of local machine address.

Try to create new database user with 127.0.1.1 and assign privilege. Remember to flush privilege.

ajsmith_codes's avatar

@spyworld

I get this error when I try to flush:

#1227 - Access denied; you need (at least one of) the RELOAD privilege(s) for this operation

AnthonyReid's avatar

Looks like the connection is fine - its the permissions on your hollys7_inexhaus user account which need review.

AnthonyReid's avatar

Database permissions for the user. Also, have you attached the user to the database? I think thats where you need to be looking.

AnthonyReid's avatar
Level 7

Do you have any strang characters in your password - such as: # ? ' //

Might need to use double quotes around your password in your config if thats the case.

2 likes
ajsmith_codes's avatar

@anthonyreid

Doing that gave me a different error message, so yay! Progress!

Now when I try to login I get "These credentials do not match our records"

At this point it must be my username and password for the app, right?

AnthonyReid's avatar

I'd lose the complex password - simplify it and remove the #

AnthonyReid's avatar

Happy to help. It was one of those weird problems - gets us all at some point. Glad its working :)

Snapey's avatar

in .env # is a comment marker. If you don't surround the password with quotes then it ends up truncated.

Please or to participate in this conversation.