CodeIgniter Forums
CL4 Connecting to a Remote AWS Database - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: CL4 Connecting to a Remote AWS Database (/showthread.php?tid=90768)



CL4 Connecting to a Remote AWS Database - cx3700 - 04-30-2024

CL 4.5.1 running on AWS Ubuntu with Plesk.

I am trying to connect to a database on our AWS test server from our AWS production server. 

When I connect to a local db on production it works but the remote (test) db connection throws a 500 error, but I can't see what the exact error is. 

Port 3306 is open on both AWS instances. 

I have set allow access from all sources. 

I have tried both the IP address and domain name in the hostname property.

Any advice?


PHP Code:
    public array $default = [
        'DSN'      => '',
        'hostname' => '54.200.xxx.xxx',
        'username' => 'test',
        'password' => 'password123',
        'database' => 'test',
        'DBDriver' => 'MySQLi',
        'DBPrefix' => '',
        'pConnect' => false,
        'DBDebug'  => true,
        'charset'  => 'utf8',
        'DBCollat' => 'utf8_general_ci',
        'swapPre'  => '',
        'encrypt'  => false,
        'compress' => false,
        'strictOn' => false,
        'failover' => [],
        'port'    => 3306,
    ]; 

The Error

Uncaught Error.
{
    "title": "CodeIgniter\\Database\\Exceptions\\DatabaseException",
    "type": "CodeIgniter\\Database\\Exceptions\\DatabaseException",
    "code": 500,
    "message": "Unable to connect to the database.\nMain connection [MySQLi]: Connection refused",
    "file": "/var/www/vhosts/mydomain.com/install.mydomain.com/system/Database/BaseConnection.php",
    "line": 428,
    "trace": [
        {
            "file": "/var/www/vhosts/mydomain.com/install.mydomain.com/system/Database/BaseConnection.php",
            "line": 575,
            "function": "initialize",
            "class": "CodeIgniter\\Database\\BaseConnection",
            "type": "->"
        },
        {
            "file": "/var/www/vhosts/mydomain.com/install.mydomain.com/app/Models/ChecklistModel.php",
            "line": 35,
            "function": "query",
            "class": "CodeIgniter\\Database\\BaseConnection",
            "type": "->"
        },
        {
            "file": "/var/www/vhosts/mydomain.com/install.mydomain.com/app/Controllers/Checklist.php",
            "line": 58,
            "function": "getSiteByPVIN",
            "class": "App\\Models\\ChecklistModel",
            "type": "->"
        },
        {
            "file": "/var/www/vhosts/mydomain.com/install.mydomain.com/app/Controllers/Checklist.php",
            "line": 48,
            "function": "get_site_information",
            "class": "App\\Controllers\\Checklist",
            "type": "->"
        },
        {
            "file": "/var/www/vhosts/mydomain.com/install.mydomain.com/system/CodeIgniter.php",
            "line": 943,
            "function": "check_site_information",
            "class": "App\\Controllers\\Checklist",
            "type": "->"
        },
        {
            "file": "/var/www/vhosts/mydomain.com/install.mydomain.com/system/CodeIgniter.php",
            "line": 503,
            "function": "runController",
            "class": "CodeIgniter\\CodeIgniter",
            "type": "->"
        },
        {
            "file": "/var/www/vhosts/mydomain.com/install.mydomain.com/system/CodeIgniter.php",
            "line": 361,
            "function": "handleRequest",
            "class": "CodeIgniter\\CodeIgniter",
            "type": "->"
        },
        {
            "file": "/var/www/vhosts/mydomain.com/install.mydomain.com/public/index.php",
            "line": 79,
            "function": "run",
            "class": "CodeIgniter\\CodeIgniter",
            "type": "->"
        }
    ]
}


RE: CL4 Connecting to a Remote AWS Database - kenjis - 04-30-2024

See log file:
https://codeigniter4.github.io/CodeIgniter4/testing/debugging.html#codeigniter-error-logs


RE: CL4 Connecting to a Remote AWS Database - kenjis - 04-30-2024

Quote:Unable to connect to the database.\nMain connection [MySQLi]: Connection refused
The MySQL server did not accept your connection.
Check the server or network configuration.

Quote:Port 3306 is open on both AWS instances.


How did you know that? If it is really open, the error message would be different.


RE: CL4 Connecting to a Remote AWS Database - cx3700 - 04-30-2024

3306 is open in both AWS Lightsail and in Plesk firewall.
I can connect to the db from local code, so I know the credentials are correct.

(04-30-2024, 08:55 PM)kenjis Wrote: See log file:
https://codeigniter4.github.io/CodeIgniter4/testing/debugging.html#codeigniter-error-logs

I posted the error above. 



RE: CL4 Connecting to a Remote AWS Database - kenjis - 05-01-2024

(04-30-2024, 10:48 PM)cx3700 Wrote: 3306 is open in both AWS Lightsail and in Plesk firewall.
I can connect to the db from local code, so I know the credentials are correct.

I don't know what AWS Lightsail and Plesk firewall mean exactly,
but the error message says the port is not open from the remote host.


RE: CL4 Connecting to a Remote AWS Database - cx3700 - 05-01-2024

(05-01-2024, 06:09 PM)kenjis Wrote:
(04-30-2024, 10:48 PM)cx3700 Wrote: 3306 is open in both AWS Lightsail and in Plesk firewall.
I can connect to the db from local code, so I know the credentials are correct.

I don't know what AWS Lightsail and Plesk firewall mean exactly,
but the error message says the port is not open from the remote host.

No it doesn't. It says the connection was refused but that could be for a lot of reasons. Lightsail is the interface you use to manage ports and server settings on AWS.