Jump to content

Database access denied after moving from localhost to live server


zkriszti
 Share

Recommended Posts

Hello,

I've been trying to move a site from localhost to live environment. I have done everything step by step as Ryan suggested here. I get the following error message:

"Exception: SQLSTATE[28000] [1045] Access denied for user" (see attached image).

What I have tried / made sure about:

  • my db credentials in site/config.php are OK, I have checked a thousand times
  • $config->userAuthSalt untouched
  • changed $config->httpHosts value (from array('localhost'); to array('mydomain.hu'); )
  • I have deleted then reuploaded all site files
  • .htaccess contains only the default ProcessWire directives, nothing else special
  • emptied the site/assets/sessions folder
  • searched this forum and Google extensively before posting... ;)

...and still getting the error. This was just a regular localhost installation on wamp with no exotic settings like multisite, etc.

Could you please point me in the right direction? Thank you very much in advance. 

 

 

 

siteerror2.PNG

Link to comment
Share on other sites

  On 10/4/2017 at 9:32 AM, zkriszti said:

my db credentials in site/config.php are OK, I have checked a thousand times

Expand  

have you:

1) exported your localhost database?

2) Created a new database on the live or web hosting location?

3) Imported the localhost database into the newly created database?

4) Made changes to your site/config.php to reflect the credentials in the newly created database?

_

Link to comment
Share on other sites

Try this: 

Create a PHP file with this script (https://gist.github.com/chales/11359952), enter the right credentials and test it, it is likely not working but now you can be sure it is not PW. Try to find the correct settings for your database at your hostings provider FAQ.

[edit]Working mysqli version for PW, place this file in /site/ and test away!

<?php

# Fill our vars and run on cli
# $ php -f db-connect-test.php

define('PROCESSWIRE', 300);

class DummyConfig {

    private $data = [];

    public function __set($name, $value) {
        $this->data[$name] = $value;
    }

    public function __get($name) {
        return $this->data[$name];
    }
}

$config = new DummyConfig();
include 'config.php';

$dbhost = $config->dbHost;
$dbname = $config->dbName;
$dbuser = $config->dbUser;
$dbpass = $config->dbPass;

$connect = mysqli_connect($dbhost, $dbuser, $dbpass) or die("Unable to Connect to '$dbhost'");
if (!$connect) {
    echo "Error: Unable to connect to MySQL." . PHP_EOL;
    echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
    echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
    exit;
}

mysqli_select_db($connect, $dbname) or die("Could not open the db '$dbname'");

$test_query = "SHOW TABLES FROM $dbname";
$result = mysqli_query($connect, $test_query);
$tblCnt = 0;

while($tbl = mysqli_fetch_array($result)) {
    $tblCnt++;
    echo $tbl[0]."<br />\n";
}

if (!$tblCnt) {
    echo "There are no tables<br />\n";
} else {
    echo "There are $tblCnt tables<br />\n";
}

 

  • Like 1
Link to comment
Share on other sites

  On 10/4/2017 at 10:00 AM, EntitySelf said:

Try this: 

Create a PHP file with this script (https://gist.github.com/chales/11359952), enter the right credentials and test it, it is likely not working but now you can be sure it is not PW. Try to find the correct settings for your database at your hostings provider FAQ.

Expand  

I get this:

" Warning: mysql_connect(): Access denied for user '...'@'[IP]' (using password: YES) in /.../dbtest.php on line 8
Unable to Connect to 'sql' "

- so in this case the problem most probably lies at the histing provider side, ami I right?

Link to comment
Share on other sites

Sorry, I made an updated version for you, check my previous post.

Yes, most likely the credentials, host name or port is incorrect.

[edit again]

You are using an IP address now, did you try using a hostname? 

127.0.0.1 = localhost

etc, I remember that this actually does matter when connecting to a DB!

Link to comment
Share on other sites

  On 10/4/2017 at 10:16 AM, EntitySelf said:

Sorry, I made an updated version for you, check my previous post.

Yes, most likely the credentials, host name or port is incorrect.

[edit again]

You are using an IP address now, did you try using a hostname? 

127.0.0.1 = localhost

etc, I remember that this actually does matter when connecting to a DB!

Expand  

OK, I haven't yet seen the third version that you have posted here, but now tried with that one. It says now:

" 404 page not found (no site configuration or install.php available) "

Link to comment
Share on other sites

I am confused, what did you mean with the third version and how did you name the script file?

If you named if "dbtest.php" and upload it to 'mysite.com/site/' and then opened it from the address bar 'mysite.com/site/dbtest.php' you get a 404 error? 

[sadly]I have to go in like 10 minutes, be back +- 7 hours from now.

Link to comment
Share on other sites

Ok, after a brief Teamviewer session, it turns out that the problem is beyond PW and @zkriszti, because through neither phpMyAdmin nor adminer could we access the mysql instance. PHP cannot communicate with MySQL server at all. Either the MySQL server does not run on the localhost, but on a different server on the network, or it's not running, which I doubt, because the hosting seems to be shared, so that would mean no service for a lot of sites. Contacting the provider seems to be the best option.

  • Like 2
  • Thanks 1
Link to comment
Share on other sites

OK, so the host provider told me that I had done something wrong (had chosen the wrong server) when creating the database, then just a minute later they informed me that they have corrected the error. (?) :o This made it possible to log in to phpMyAdmin, and import my db without any problems, but the frontend was still inaccessible giving me 404 error (as far as I got it, it was some kind of mismatch between index.php and config.php).

No magic helped there, so I deleted all the site files via FTP, then reuploaded them. Of course, here I needed to modify config.php accordingly (as I reuploaded a localhost installed site). After this step, my frontend came alive & working. :rolleyes:

Still struggling with some minor issues, but that is for another day. :) 

  • Like 4
Link to comment
Share on other sites

  • 3 years later...

I had this exact style of error message also when moving from one server to another, in my case it came from a different issue than the OP (OP's looked to be a problem with the web host). In case anyone else is also experiencing this, I found I had made a simple error: on my new host where I created a new database user, I had forgotten to add the database user as a privileged user of the database. Doing that fixed the problem: in a cPanel host, just go to Databases > MySQL databases and then "Add User to Database".  After making that change, my site was live!

Yes, it's a total facepalm moment on my part, but it IS surprisingly easy to forget after creating a new database and importing the old one into it, then creating a new db user and password, changing the equivalent credentials in site/config.php to match the new info and... it doesn't work! So when creating the database user, remember that it needs to be added as a privileged user of that database.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...