I want to connect Laravel with Postgresql database
when I run
php artisan migrate
I get this error
SQLSTATE[08006] [7] timeout expired (SQL: select * from information_schema.tables where table_schema = public and table_name = migrations)
my .env
DB_CONNECTION=pgsql
DB_HOST=projects.cggts***.rds.amazonaws.com
DB_PORT=5432
DB_DATABASE=projects
DB_USERNAME=*********
DB_PASSWORD=*********
It'll probably inbound VPC problem on AWS . You have to update IP range for your RDS db. You'll find it under EC2->Network & Security->Security Groups . Have fun ;)
Related
In my local laravel environment I don't have any problems connecting.
But in production I'm getting this:
return "SQLSTATE[08006] [7] timeout expired (SQL: select * from "document")" in all routes that queries the bank..
DB_CONNECTION=pgsql
DB_HOST=**.**.**.**
DB_PORT=5432
DB_DATABASE=***********
DB_USERNAME=************
DB_PASSWORD=***************
Problem was in the cache, noticed the password change for an incorrect one and I clicked the new one again and gave p
php artisan config:cache
started working again
I got a laravel app (9.19.0) and php (8.1.1) linked to a mariadb database.
Each part of the app is in a specific docker container.
When I try to do php artisan migrate to build my tables, I got the error
SQLSTATE[HY000] [2002] A connection attempt failed because the connected party did not respond properly after a certain amount of time or an established connection failed because the connecting host did not respond (SQL: select *
from information_schema.tables where table_schema = mydatabasename and table_name = migrations and table_type = 'BASE TABLE')
\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:70
PDO::__construct("mysql:host=172.19.0.3;port=3306;dbname=mydatabasename", "username", "password", [])
The point is when I run an API request on the same application, I can access my database with the exact same .env file.
I tried to :
php artisan cache:clear : Clear cache but no changes
Reinstall completely my docker containers (volumes & containers) : No changes
Change the DB_HOST parameter from IP to container name : No changes
Create manually the table migrations : No changes
For me, the probleme come from the request returned in the error message, because when I type the exact same query select * from information_schema.tables where table_schema = mydatabasename and table_name = migrations and table_type = 'BASE TABLE' I got an error saying that mysql cannot found the field mydatabasename but when I put the parameters between quotes no more errors select * from information_schema.tables where table_schema = 'mydatabasename' and table_name = 'migrations' and table_type = 'BASE TABLE'
For me, this is pure magic, why can't artisan connect to my database but my app can since they are using the same .env file and (I guess) the same underlaying method to connect to the database ?
Note : With the exact same setup, things seems to work previously
I am getting the following error
[2022-04-07 12:11:23] local.ERROR: SQLSTATE[HY000] [2002] Connection refused (SQL: select * from information_schema.tables where table_schema = swimrace and table_name = migrations and table_type = 'BASE TABLE') {"exception":"[object] (Illuminate\\Database\\QueryException(code: 2002): SQLSTATE[HY000] [2002] Connection refused (SQL: select * from information_schema.tables where table_schema = swimrace and table_name = migrations and table_type = 'BASE TABLE') at /var/www/swimrace/vendor/laravel/framework/src/Illuminate/Database/Connection.php:712)
When I run php artisan migrate
I'm running it inside the container using this command docker-compose exec workspace bash
Here my laradock .env configuration:
### MARIADB ###############################################
MARIADB_VERSION=latest
MARIADB_DATABASE=default
MARIADB_USER=root
MARIADB_PASSWORD=root
MARIADB_PORT=3306
MARIADB_ROOT_PASSWORD=root
MARIADB_ENTRYPOINT_INITDB=./mariadb/docker-entrypoint-initdb.d
Here my laravel project .env configuration:
DB_CONNECTION=mysql
DB_HOST=mariadb
DB_PORT=3306
DB_DATABASE=swimrace
DB_USERNAME=swimrace_user
DB_PASSWORD=raceswim
User and password in this last configuration was created via console into mariadb container and assigned to this account all privileges.
If I try to read database with any database ui tools (PMA, DataGrip, etc) I can see and write inside the database, but not with artisan commands.
Any suggestions?
When i run the command php artisan migrate it gives me this error:
SQLSTATE[08006] [7] could not connect to server: Connection refused
Is the server running on host "127.0.0.1" and accepting
TCP/IP connections on port 5432? (SQL: select * from information_schema.tables where table_schema = public and table_name = migrations and table_type = 'BASE TABLE')
In as much as i am using a database.sqlite file for my database
My .env file:
DB_CONNECTION=sqlite
The problem was fixed by doing the following:
I added the path for my database file in my .env, then it looked like this below
DB_CONNECTION=sqlite
DB_DATABASE='database/database.sqlite'
Then I cleared my cache using php artisan config:cache
Then I ran php artisan migrate and it worked!
I have the most basic setup in AWS:
a publicly accessible RDS instance (PostgreSQL 9.6.6 - same as my development one)
a CodeBuild project
both in the default VPC.
My application is written in Laravel 5.5 and the buildspec.yml runs ./artisan migrate --force at some point and CodeBuild outputs the following error:
[Container] 2018/03/10 19:41:36 Running command php artisan migrate --force
[Illuminate\Database\QueryException]
SQLSTATE[08006] [7] timeout expired (SQL: select * from information_schema.
tables where table_schema = public and table_name = migrations)
[Doctrine\DBAL\Driver\PDOException]
SQLSTATE[08006] [7] timeout expired
[PDOException]
SQLSTATE[08006] [7] timeout expired
Where should I start looking for an error?
You need to make sure that the RDS security group allows inbound traffic from Code Build.
Go to https://ip-ranges.amazonaws.com/ip-ranges.json
Search for CODEBUILD and choose your region.
Add the IP to the inbound rule in the RDS Security Groups.
Create a Security Group for Code Build and reference it as a source from the DBSecurity Group.