I'm trying to access a database (which exists on a different server) on my Laravel application. I keep getting the following error: SQLSTATE[HY000] [2002] Permission denied
My .env file is set up as follows (changed a bit to protect privacy):
DB_CONNECTION=mysql
DB_HOST= IP_ADDRESS
DB_PORT=3306
DB_DATABASE=DB_NAME
DB_USERNAME="laravel_user"
DB_PASSWORD="password"
I'm not sure if this is important or not but I can access the web server's database if I go to the link IP.ADDRESS/phpmyadmin
My web.php file is as follows:
Route::get('/test', function(){
return DB::select("select * from umts_list");
});
Additionally, I also went to IP_ADDRESS/phpmyadmin (where my database exists) and added a new user called laravel_user with the ability to SELECT all data and saved it with the 'password' as its password.
My attempt: I tried whatever I mentioned above and also cleared the cache since I made changes to the .env file by entering the following commands:
php artisan config: clear
php artisan cache: clear
Any help would be appreciated. Thank you.
Edit 1: On phpMyAdmin, I made sure to add the user as depicted by the following picture:
PhpMyAdmin User Account
Additionally, I also checked the port number on phpMyadmin and it is 3306 as depicted by the following image:
Port Number
My Answer:
_DB_PASSWORD=PASSWORD_
Make sure that the IP address you have entered in the DB_HOST field is correct and that the database server allows remote connections. You may need to configure the database server to allow connections from your Laravel application's server.
Additionally, check that the database user specified in the DB_USERNAME field has the necessary permissions to access the database specified in the DB_DATABASE field.
If you have confirmed that the IP address, database user, and permissions are correct, you may want to check if there are any firewall rules blocking the connection between your Laravel application server and the database server.
If you are still experiencing issues, you may want to consult with your database administrator or hosting provider for further assistance.
Rate this post
4 of 5 based on 1496 votesComments