I have a laravel 5.7.13 blog which works very well on my local server. But after deploying it to live shared cpanel server, the database won’t connect even after i have updated my .evn file.
.env updated file:
APP_NAME=EXTRAKOBO
APP_ENV=local
APP_KEY=base64:1Z6bkcUcgfoN6+cWghKDhRglrQStTg7aXaZI=
APP_DEBUG=true
APP_URL=http://localhost
LOG_CHANNEL=stack
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=ondi_myblog
DB_USERNAME=ondi_blog
DB_PASSWORD=abcd13
Below is the error that I am getting:
/home/ondi/miniblog/vendor/laravel/framework/src/Illuminate/Database/Connection.php
/**
* @param array $bindings
* @param Closure $callback
* @return mixed
*
* @throws IlluminateDatabaseQueryException
*/
protected function runQueryCallback($query, $bindings, Closure $callback)
{
// To execute the statement, we'll simply call the callback, which will actually
// run the SQL against the PDO connection. Then we can calculate the time it
// took to execute and log the query SQL, bindings and time in our memory.
try {
$result = $callback($query, $bindings);
}
// If an exception occurs when attempting to run a query, we'll format the error
// message to include the bindings with SQL, which will make this exception a
// lot more helpful to the developer instead of just the database's errors.
catch (Exception $e) {
throw new QueryException(
$query, $this->prepareBindings($bindings), $e
);
}
return $result;
}
Arguments
1. "SQLSTATE[28000] [1045] Access denied for user 'ondi_blog'@'localhost'
(using password: YES) (SQL: select count(*) as aggregate from `posts`)"
Please I will need help to resolve this issue. Thank you for your assistance
3
Answers
As you are already on server, so you can’t do artisan command.
You can do something like that.
hi the problem is in your .env romove the password i think that your phpmyadmin dont have password and root username
The problem was on DB_HOST. All these while, my DB_HOST had been 127.0.0.1. Even when I changed it to “localhost”, it still didn’t work.
But as soon as i changed it to the host server name, it worked for me at ones. The host server name can be gotten from phpMyAdmin under database in the cpanel where you import your database to. Above Database box at the top left side, your host database name is there. Just copy and paste on the DB_HOST.
Mine is mysql20001.mochahost.com (Though I removed the .mochahost.com) and that’s it, it worked for me. The new code now looks like this on the .env file: