0

I have updated a Laravel 5.5-installation to 5.8 and am now attempting to update the MySQL-installation from 5.7 to 8.0.19. The Laravel-installation is on an EC2-instance and works great with the previous RDS MySQL/Aurora installation, but the version did not cut it.

We are running this on an nginx-server.

First I got an error-message stating

(2/2) PDOException

SQLSTATE[HY000] [2002] Connection refused

Tried to change the AWS uri and use the ip instead, and got a 504 instead.

I tried to access the database through MySQL Workbench and through new PDO('mysql:host=xx-rds-staging-mysql-8.xxxxxxxxxxxx.eu-west-1.rds.amazonaws.com;port=3306;dbname=database', 'username', 'password', [0, 2, 0, false, false, false]) and... they both work perfectly from the EC2-instance.

Env-file:

DB_CONNECTION="mysql"
DB_HOST_WRITE="xx-rds-staging-mysql-8.xxxxxxxxxxxx.eu-west-1.rds.amazonaws.com"
DB_HOST_READ="xx-rds-staging-mysql-8.xxxxxxxxxxxx.eu-west-1.rds.amazonaws.com"
DB_PORT_READ_AND_WRITE="3306"
DB_DATABASE="database"
DB_USERNAME="username"
DB_PASSWORD="password"

config/database.php

'mysql' => [
    'read' => [
        'host' => env('DB_HOST_READ', '127.0.0.1'),
    ],
    'write' => [
        'host' => env('DB_HOST_WRITE', '127.0.0.1'),
    ],
    'port' => env('DB_PORT_READ_AND_WRITE', '3306'),
    'driver' => 'mysql',
    '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' => '',
    'strict' => false,
    'engine' => null,
    'sticky' => true,
    'version'     => 8,
    'modes'  => [
        #'ONLY_FULL_GROUP_BY',
        'STRICT_TRANS_TABLES',
        'NO_ZERO_IN_DATE',
        'NO_ZERO_DATE',
        'ERROR_FOR_DIVISION_BY_ZERO',
        'NO_ENGINE_SUBSTITUTION',
    ],
    'options' => [
        PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT => false,
    ],
],

I have cleared the cache by all the artisan-commands and by deleting the cache-folder.

I am rubbish at asking for help here, not ever certain what information I need to share to make my case.

My first thought is that there ought to be some setting in Laravel which I could swap to make this work, but I have no idea what it could be.

The mysql-server does not run on the same machine as the laravel-application and AWS has not offered a public ip, just the uri.

What makes it even stranger is that I can enter php artisan tinker and run, for example, User::first(); and it will fetch the appropriate row from the database, without any issue.

Richard Atterfalk
  • 462
  • 1
  • 10
  • 23
  • Did you refresh config cache? – user3647971 Jul 10 '20 at 23:06
  • There's more information on caching [here](https://laravel.com/docs/5.8/configuration#configuration-caching) and more information on the error message in general with laravel 5 [here](https://stackoverflow.com/questions/35394230/sqlstatehy000-2002-connection-refused-within-laravel-homestead). That question also shows what you should be looking at to find the problem. – user3647971 Jul 10 '20 at 23:14
  • I shall update my question further with the steps I’ve taken so far. Cache has been cleared, even deleted the cache-folder to be safe, quadruple-checked the env-file and all the data is correct. Used it to connect through PDO. Copied the connection-string from the error-message and got a connection as well. The mysql-server does not run on the same machine as the laravel-application and AWS has not offered a public ip, just the uri. – Richard Atterfalk Jul 11 '20 at 01:12
  • 1
    To be honest it really sounds like it's a config issue since you can connect from same machine using PDO. `php artisan cache:clear php artisan config:clear php artisan config:cache php artisan view:clear` is what I'd run just to rule out cache issues. – user3647971 Jul 11 '20 at 01:48
  • The cache has been cleared, but the issue remains. I wonder if Laravel used, or don’t uses, any option that could cause this. – Richard Atterfalk Jul 11 '20 at 09:30

1 Answers1

0

No details informaton but you can review below points:

  1. Verify your Laravel/php config or connection file didn't change and have same settings as before.
  2. Did you set any zone specific resstriction in RDS? Does your testing environment complies it?
  • The config-file is all good. I shall have to double check the zone-restrictions, but would that cause issue to laravel which is not detected when connecting from the native pdo-class? – Richard Atterfalk Jul 11 '20 at 01:18
  • So it means zone is fine as you are successful to connect using native pdo. In that case you need to debug connection string/parameter using ìn Laravel class/function. May be it has any default setting such as port or other stuffs that does't match with your RDS server. – Maftahur Rahman Jul 11 '20 at 01:42
  • Yeah, here is the kicker: artisan tinker -> User::first() retrieves an entry while the site cannot connect. – Richard Atterfalk Jul 11 '20 at 09:31