I followed every tutorial from Amazon to set up the RDS Database then to set up the VPC, the subnet, and the Security Groups but I still can't connect to the Database using Laravel command.
However, I can connect to the Database using MySQLWorkbench...
This is the error I got when I use the command "php artisan migrate"
Every help will be more than appreciate, thank you Guys.
I'm taking these settings right out of my RDS instance and the Laravel application that uses it.
The first thing you have to do after setting up your RDS database is to allow the database instance to be accessed publicly. This can be done from your AWS console by going to RDS > DB Instances > your database instance > Modify (top left corner). Then scroll down to the Network and Security section and select 'Yes' for public accessibility.
Also double check your Security groups to make sure there is a rule allowing incoming connections to port 3306.
In your Laravel application's .env file and update the database values.
DB_HOST should contain the endpoint specified on the Connectivity and security section of the RDS dashboard. DB_PORT should remain at 3306. Then specify the database name in DB_DATABASE and the database credentials in DB_USERNAME and DB_PASSWORD.
These are the settings I'm using to connect my Laravel application to an RDS MySQL database.
It's difficult to say but it looks like you have the incorrect DB name.
Double check your RDS db name and the environment variable DB_DATABASE
Related
I am working on a Laravel application. I using Redis and I am using AWS ElasticCache service for that. I am trying to connect to the Redis from my Laravel application. But it is timing out. This is what I have done.
I installed the Predis library by running the following command.
composer require predis/predis
Then I created a Redis instance in the ElastiCache service console enabling AUTH setting my password token.
Then I set the variables in the .env files.
CACHE_DRIVER=redis
REDIS_CLIENT=predis
REDIS_HOST=master.laravelredistest.8sm3xo.euw1.cache.amazonaws.com
REDIS_PASSWORD=mypassword
REDIS_PORT=6379
When I run the code to connect to the Redis, I got the following error.
Operation timed out [tcp://master.laravelredistest.8sm3xo.euw1.cache.amazonaws.com:6379]
What is missing with my configuration and how can I fix it?
I also updated the security group of Redis to allow the EC2 instance's security group in the inbound rules as follows:
I am getting this error this time:
I edited the SG of Redis to add the following inbound rule too.
The security groups are in the same VPC too as you can see in the screenshot:
This sounds like a security group issue causing the timeout.
Elasticache clusters are always private so if you're using a public ip address, this will need to be updated to be the private ip address range of your instance/subnet/VPC.
An Elasticache cluster is a resource in your VPC, therefore network transit needs to be allowed for the cluster to be accessible.
More information is available in the Accessing Your Cluster page.
Additional Configuration
This is the issue. I also needed to delete the existing Redis instance and create another one without AUTH token enabled.
I’ve now tried to create a serverless Aurora (MySQL compatible) database and connect to it for two days, and I just can’t seem to get it to work. Supposedly I should have been able to get it up and running in five minutes.
In any case, I created am Aurora Serverless database in the US East (N. Virginia) region (us-east-1), and have been able to connect to it with the AWS Query Editor. I also have an EC2 server in the same region, and have given the Aurora database the same security group (under RDS > Security Group), and in the security group I have opened for MYSQL/Aurora (TCP, 3306) from all sources. When I click the modify button on the database, there is also another (VPC) Security Group listed (rds-launch-wizard-4), which was created automatically. This one I also located under my EC2 dashboard and gave access to all ports from all sources (inbound), and to all ports (outbound). And there is a networking VPC & subnet group, which I don’t know what to do with, if anything.
I try to connect to the database, using this command line command:
mysql -h hest2.cluster-xxxxx.us-east-1.rds.amazonaws.com -P 3306 -u root –p
It generates an error “ERROR 2003 (HY000): Can't connect to MySQL server on” on both my EC2 instance, my local computer and on other online servers.
From the EC2 instance, try doing a telnet on the DB port to test if all your security group settings are applied correctly.
telnet hest2.cluster-xxxxx.us-east-1.rds.amazonaws.com 3306
If the connection does go through, then the issue is with your client code. Cross check that you have wired the right endpoint in your code.
If the telnet connection does not group (I'm guessing that it would not), then it is guaranteed that your security group settings are not set correctly. In order to debug this further, we would need more details on:
The list of vpc security groups associated with your cluster.
The details of each of these vpc security groups (You've mentioned that
you've opened up everything, but I'd like to see the exact rules in
place)
As for laptop and other servers - If they are outside the VPC, then it would not work. Aurora Serverless is accessible only from within the VPC as of now.
I have created a VPC. And inside that vpc in same subnet there are two ec2 instances. There is a deployed application on the first one and on the second one there is installed mysql. I have set up the application to connect to the instance with the installed db but with no success. I will copy the security groups configuration and the db configuration.
How to make both of these two instance communicate and the application from the first instance start using the db on the second. Both of them have public ip and can ping each other.
DB connection
spring.jpa.database-platform=org.hibernate.dialect.MySQL5InnoDBDialect
spring.jpa.hibernate.ddl-auto=update
spring.datasource.driverClassName=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://some_ip:3306/demo
spring.datasource.username=root
spring.datasource.password=root
Security groups
There are two security groups and both of the are assign to every ec2 instance.
The added id is the ID of this group.
EDIT1 - of the second security group
In your security group you are not allowing port 3306 which the database needs to communicate over.
Install mysql-client on your app server you can use the cli to see if you can connect to the database MySQL server using:
mysql -h mysql://some_ip -u root
This has been killing me all day.
I've set up Elastic Beanstalk, working fine.
Set up RDS, working fine and can access from my laptop.
But when i try to connect to the RDS from my ES application i get a timeout error.
Extra info is that i'm using a Laravel application, connecting to a MYSQL database. All of my environment variables have been loaded and accepted fine.
I'm almost certain it's a security groups setting, but the docs are so tremendously bad for AWS that i haven't got a clue what to do!
Any help?
Answer was to go to Services > VPC
Under the Security section, click Security groups.
Click the RDS group, then Inbound Rules.
Edit, then add a rule:
Select MYSQL, change the port, then the IP should be custom IP and type in the ID of your Elastic Beanstalk security group / groups (No idea why i have 2)
I have created an ec2 instance and followed all steps according to AWS documentation, But I am unable to connect to database from the php files in html folder. Below is the error
Warning: mysqli_connect(): (HY000/1130): Host
'ip-172-31-28-115.us-west-2.compute.internal' is not allowed to
connect to this MySQL server in /var/www/html/test/test.php on line 11
Unable to connect to MySQL
The Php files are not getting connected to the database that is created on instance.
Note: I also tried creating new user and granted privileges to the new user but no luck!
It would be great if you can assist us through problem, since we have already spent lot of time experimenting on this.
Things to check for MySQL connection:
--/etc/my.cnf to ensure that listening on the right port(s) ip(s). 3306 default.
--Open port 3306 in AWS to ensure that client can access
--Grant privs on database to user that is connecting.
--Examine mysql logs and apache error logs for errors.
can you try running this? I think it has to do with permissions.
GRANT ALL PRIVILEGES ON . TO 'root'#'%';
FLUSH PRIVILEGES;