I have successfully completed deploying my application on elastic beanstalk. But when I call the URL it shows (I have exported my table to RDS DB instance)
ErrorException in Connector.php line 47:
SQLSTATE[HY000] [2002] Connection timed out (View: /var/app/current/local/resources/views/themes/default1/client/cart.blade.php)
My database.php configuration is:
'mysql' => [
'driver' => 'mysql',
'host' => 'rds.cvp31y7ebg1x.us-west-2.rds.amazonaws.com:3306',
'database' => 'rdsdb',
'username' =>'rdsuser',
'password' => '******',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
],
Please help me to figure out this problem.
Thanks.
1) You may provide the port using the "port"-key in config:
'port' => env('DB_PORT', '3306'),
2) Check RDS Security groups, or - as most probably you're using RDS inside a VPC:
3) Check VPC Security groups. Attach VPC security groups to your RDS instance and whitelist your IP / your account (bad practice) / your instance or scaling group in these VPC security groups. Remember: If you use RDS inside VPC, it's the VPC Security group that's important for RDS!
Related
I am trying to connect a laravel application to a remote database.The connection works successfully on my local machine but does not work in the production environment.The laravel application is connected to its own database hosted in the cloud but i want to access another database hosted by another provider.Hence,I did the following:
In Config/database file in laravel folder,I added another mysql connection
config the .env file as well.
'mysql' => [
'driver' => 'mysql',
'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' => '',
'strict' => false,
'engine' => null,
],
'mysql3' => [
'driver' => 'mysql',
'host' => env('DB_HOST_THIRD','localhost'),
'port' => env('DB_PORT_THIRD'),
'database' => env('DB_DATABASE_THIRD',''),
'username' => env('DB_USERNAME_THIRD',''),
'password' => env('DB_PASSWORD_THIRD',''),
],
Then in .env file:
DB_CONNECTION=mysql3
DB_HOST_THIRD=remote IP
DB_PORT_THIRD=3306
DB_DATABASE_THIRD=Remote DB Name
DB_USERNAME_THIRD=Username
DB_PASSWORD_THIRD=password
With the above setting, i can connect to the remote database successfully on my local machine.
Upon deployment, I am unable to connect to this remote database,even though a designated user has been created and access granted through the control panel.This remote database is hosted by GoDaddy and i have called but they said nothing is blocking my application, that everything is ok from their end. Below are what I have done:
I am able to connect the remote Database using Sqlyog, Mysql client successfully.
I connected to Terminal on the Remote Cpanel and try to grant all access to the User at its IP but the response is: "Access denied for user 'username#Remote IP'(using password:YES)".
From web application, the error is : "SQLSTATE[HY000] [2002] Connection refused".
I have telnet the remote IP with port 3306, which respond well. Please, can someone help me, perhaps there are things i am missing or is this kind of issue peculiar to Godaddy shared hosting?. I have checked the following from Stackoverflow:
Enable remote MySQL connection: ERROR 1045 (28000): Access denied for user
I can`t find too much documentation about connecting Drupal7 website with SQL Google database. Does anybody have experience with it? I trying to split Drupal website on VM instance and mysql database on SQL Google storage. After that, change settings.php in Drupal:
$databases['default']['default'] = array(
'database' => 'DATABASE',
'username' => 'USERNAME',
'password' => 'PASSWORD',
'host' => 'Public_IP_of_Google_SQL',
'driver' => 'mysql',
'port' => 3306 (I try 1433 also),
'prefix' => '',
);
}
On SQL instance I have enabled firewall for tcp ports:3306,1433
However, I always get error
PDOException: SQLSTATE[HY000] [2002] Connection refused in lock_may_be_available() (line 167 of /home/public_html/includes/lock.inc).
Can anybody help? What can I do on Drupal side to connect website with external database?
I have a Heroku app where I'm hosting my Laravel app. I started the development initially with MySQL, so I wanted to continue doing so using Amazon's RDS service. I create the instance there and managed to successfully connect via my MySQL client, the console etc.
The problem is that the Laravel app can't connect the database after numerous desperate attempts for me to fix it. I have found some articles suggesting the use of DATABASE_URL environment variable is mandatory, so I added it via the Heroku app settings. It looks like so:
mysql://myusername:mypass#myhostnamefromamazon/mydb?sslca=/app/storage/certs/amazon-rds-ca-cert.pem
I found this solution on Heroku's website. I have placed the amazon-rds-ca-cert.pem file on my Laravel's storage folder, like so: /app/storage/certs/amazon-rds-ca-cert.pem
This didn't solve my issue, so then I kept looking and found a Stackoverflow question which had this issue on Lumen. I adjusted my config/database.php according to the answer, but it's still not working for me!
<?php
$credentials = get_db_credentials();
$config = [
'default' => env('DB_CONNECTION', 'mysql'),
'connections' => [
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', $credentials->host),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', $credentials->database),
'username' => env('DB_USERNAME', $credentials->username),
'password' => env('DB_PASSWORD', $credentials->password),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
],
],
];
if (env('APP_ENV') == 'production') {
$config['connections']['mysql']['options'] = [PDO::MYSQL_ATTR_SSL_CA => '../storage/certs/amazon-rds-ca-cert.pem'];
}
return $config;
The get_db_credentials() function simply parses the DATABASE_URL environment variable.
The exact exception that I get is:
[2018-10-25 19:32:16] production.ERROR: SQLSTATE[HY000] [2002] Connection timed out {"exception":"[object] (Doctrine\\DBAL\\Driver\\PDOException(code: 2002): SQLSTATE[HY000] [2002] Connection timed out at /tmp/build_05920c42a6de0a378402b798320d3f04/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:50
I'm totally lost on this and unsure how to proceed.
Your AWS Security Groups must permit traffic from Heroku's IP address range.
https://devcenter.heroku.com/articles/amazon-rds
You must grant Heroku dynos access to your RDS instance. The recommended way to do this is to configure the RDS instance to only accept SSL-encrypted connections from authorized users and configure the security group for your instance to permit ingress from all IPs, eg 0.0.0.0/0.
I'm getting this error when trying to connect to an SQL Server DB from Laravel 4.2.
Here's my DB config:
'connections' => array(
'sqlsrv' => array(
'driver' => 'sqlsrv',
'host' => 'example.noip.me',
'database' => 'db',
'username' => 'sa',
'password' => 'pass',
'prefix' => '',
),
),
//...
It works perfectly in my home computer, but not in production. This project is in a hosting service, so I can't change much of the config (can still use ini_set though).
I tried adding the port to the server address but it didn't work.
Edit: I forgot to mention that the hosting and the database server are on different computers, so it could be a security configuration problem.
I contacted tech support and it turned out to be a matter of configuration in the hosting server (Remote Database Access Hosts, which I thought was for MySQL only).
I am having issues trying to work with a Cloud SQL instance and Laravel. I was able to do local dev work on a Cloud SQL instance with Python but I can't seem to get it with PHP.
Here is the error I get:
SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/cloudsql/project:instance-db'
Here is my app/config/database.php:
<?php
return array(
'fetch' => PDO::FETCH_CLASS,
'default' => 'mysql',
'connections' => array(
'mysql' => array(
'driver' => 'mysql',
'unix_socket' => '/cloudsql/my-project:instance-id',
'host' => '',
'database' => 'my_database',
'username' => 'root',
'password' => '',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
),
),
'migrations' => 'migrations',
);
It all works when deployed just not locally.
You cannot connect to CloudSQL from your local machine right now. For testing you should use a local MySQL instance the CloudSQL instance when running in production.
You should be able to assign an IP address to your Cloud SQL instance and allow your own network to access the instance in the management console.
Assigning an IP address will cost extra.