1

I'm working on a fun little PHP web application (a manager for my repeating, daily tasks), mostly for the exercise. The 'production' server is a bit limiting, and I cannot view httpd's (Apache's) error logs there, so I've set up my own local httpd as a development server (just good sense). However, my web app makes use of a MySQL database. I will create a local one eventually, but I thought, to make things easier to start, I would just use the remote one. SQLSTATE[HY000] [2002] Permission denied.

This is what came back each time I tried running the web application from my local httpd. I'm using PHP's PDO database interface, and its mysql driver, and it works when deployed on the remote server. I made sure that my remote server had permissions for my local user. I tested connecting from my local machine from the mysql client, and it worked. I tested the PHP connection statement from the command-line and ... it worked. It is only causing a problem when running within the web application.

Please tell me how to solve this issue. This is the site on which i am getting error pickprogress.com

Ayyan Alvi
  • 759
  • 2
  • 9
  • 24
  • Maybe in localhost you have "user: root; password: ;" and in production you have "user: normal-user; password: asdlk2423dgfgklkl" and you don't change these parameters? Show more code to help – Justinas Jan 08 '16 at 11:10
  • Can you include the code that returns the error? – David Rushton Jan 08 '16 at 11:12
  • no i am trying to solving this issue since last 6 hours checked each and every thing. changed host name to 127.0.0.1 checked user name nd paswrds. And if user name and paswrods are wrong then it gives another exception not this – Ayyan Alvi Jan 08 '16 at 11:13
  • Have you reffered this link? http://stackoverflow.com/questions/20723803/pdoexception-sqlstatehy000-2002-no-such-file-or-directory – Ravi Hirani Jan 08 '16 at 11:13
  • Log into your mysql instance, and check what grants the user you're trying to connect with has. I think the user is probably limited to connections from a specific IP and won't accept your connection from local as a result. – David Barker Jan 08 '16 at 11:15
  • ravi this error is different i am having exception related to permission denied. The link you gave it's related to exception `PDOException SQLSTATE[HY000] [2002] No such file or directory` – Ayyan Alvi Jan 08 '16 at 11:15
  • what can be the solution? – Ayyan Alvi Jan 08 '16 at 11:19
  • The remote mysql is it a shared hosting? – Maytham Fahmi Jan 08 '16 at 12:42
  • YES IT'S A SHARE HOSTING – Ayyan Alvi Jan 08 '16 at 12:43

2 Answers2

7

Some various server provider gives us their database server name. And instead of writing localhost or 127.0.0.1 we have to write their given server name.

I was trying to solve this problem since last 8 hours but didn't found single solution but anyhow I have now solved it.

halfer
  • 19,824
  • 17
  • 99
  • 186
Ayyan Alvi
  • 759
  • 2
  • 9
  • 24
0

IN my setuation .env file has the following:

DB_HOST=127.0.0.1

i change it to this:

DB_HOST=localhost

and it's working ...

i'm in local machine (linux fedora ) with apache server

owis sabry
  • 154
  • 9