Laravel - Database connection works on tinker but not website or APIs

194 views Asked by At

I am trying to point a remote database (from another IP) to my laravel setup in AWS EC2 instance. I have added the credentials in env like this (showing random credentials)

DB_CONNECTION=mysql
DB_HOST=150.150.150.150
DB_PORT=3306
DB_DATABASE=dev
DB_USERNAME=test-dev
DB_PASSWORD=password

The remote IP I have added in DB_HOST. This way, tinker seems to be working fine and I can fetch the records in table but the website and APIs timeout and remaining in loading state forever.

I came across this post, and tried this command

setsebool -P httpd_can_network_connect_db 1

but it returns this message

Could not change active booleans: Invalid boolean

I have also tried to access the mysql database through CLI in the EC2 instance

mysql -u test-dev -h 150.150.150.150 -p

And that works but not the website.

I do not have any more leads on this issue and will appreciate any pointers

1

There are 1 answers

1
Bismark Asiedu Asante On

Please check if SELinux is enabled. SELinux has to be enabled to allow some outgoing connections to work especially MySQL connection.

You can follow this guide to get it to work. How to Disable or set SELinux to Permissive mode