1

I am trying to use my project on godaddy but it is constantly giving me an error:

SQLSTATE[28000] [1045] Access denied for user 'nagesh'@'ip-address of the website' (using password: YES) (SQL: select * from admins where email = admin limit 1).

Although my credentials should be correct as they are created in the godaddy cpanel but still I am having this error. I searched a lot on stackoverflow and tried many solutions but nothing seems to be working. This is my .env file:

APP_ENV=local
APP_KEY=base64:Qx5MJdayISVHcd5p9nW0zJvb4BC6jyWD9BySf4j8yis=
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=http://localhost

DB_CONNECTION=mysql
DB_HOST="IP address of the website"
DB_PORT=3306
DB_DATABASE=ncminsti_ncm
DB_USERNAME="username i created using the cpanel's add new user form"
DB_PASSWORD="password created with above user."

BROADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null

PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=

I believe am doing some mistake in my .env file. Probably the DB_Host field is wrong. I am new to laravel and not sure what should be the correct configuration for .env file. Please help me in connecting to the DB. Thank you.

lloiacono
  • 4,714
  • 2
  • 30
  • 46
Nagesh Katna
  • 679
  • 2
  • 7
  • 27
  • DB and app server are on the same host? Have you tried connecting to your DB server directly? – lloiacono Feb 26 '18 at 07:28
  • yes.. the files are on the same host and i dont know how can connect to DB Server directly. Can you suggest how? – Nagesh Katna Feb 26 '18 at 07:29
  • Depends which OS you are using, but I think MySQL Workbench is available for all, so try it out. Also you could use mysql-client on the terminal: `mysql -h IP_HERE -u USER_HERE -p`. No need to type the password as part of the command, it will be prompted as you press enter. https://stackoverflow.com/questions/15872543/access-remote-database-from-command-line – lloiacono Feb 26 '18 at 07:36
  • You should read more about two topics: 1) creating and managing users in mysql: https://dev.mysql.com/doc/refman/5.7/en/adding-users.html 2) anything related to db management on godaddy: https://www.godaddy.com/help/find-your-database-hostname-23889 While these may not be exactly what you need they will get you reading about the platforms you are using. This information may not be helpful today but it might lead you to your answer. For example, the godaddy page mentions using localhost as the ipaddress, not the ip of your website. – Andrew Cotton Feb 26 '18 at 07:43
  • @NageshKatna did you ever get a solution for this?? – James Wolfe Jun 19 '19 at 17:00

2 Answers2

0

If website and database are on the same server, then:

DB_HOST=127.0.0.1

Daniel
  • 1
  • 1
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Sep 05 '22 at 03:19
0

You will need to try and connect to your database first:

mysql -h <thehost> -u <theuser> -p

This will either ask you to type your password or report an error. Since Laravel could not connect to your database (ultimately generating something like the above), it is safe to assume that the command above will fail. You will need to find out what the problem is, solve that and then apply the solution to your Laravel environment as well.

It is very possible that you had a typo in the username/password or defined your hostname incorrectly. It is possible that you just need to connect to localhost (127.0.0.1), but it's also possible that the server is located either on a remote computer or an image (like a Docker image). You may also need to connect to a VPN or whitelist your IP address. Try contacting your sysadmin to find out how you can connect to your database on the Command-Line Interface and once that works, apply the same idea in your Laravel config.

Lajos Arpad
  • 64,414
  • 37
  • 100
  • 175