Welcome Guest, Not a member yet? Register   Sign In
CL4 Connecting to a Remote AWS Database
#1

(This post was last modified: 04-30-2024, 08:59 PM by kenjis.)

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": "->"
        }
    ]
}
Reply
#2

See log file:
https://codeigniter4.github.io/CodeIgnit...error-logs
Reply
#3

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.
Reply
#4

(This post was last modified: 04-30-2024, 10:50 PM by cx3700.)

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/CodeIgnit...error-logs

I posted the error above. 
Reply
#5

(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.
Reply
#6

(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.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB