Reputation: 417
Ive just built my new app in Laravel 5.1 and im trying to push it live. When i try to composer install i am getting this error.
[PDOException]
SQLSTATE[HY000] [1045] Access denied for user ''@'localhost' (using password: NO)
Script php artisan clear-compiled handling the post-install-cmd event returned with an error
[RuntimeException]
Error Output:
I am using a environment file on both local and production so i have no idea whats going on. Any ideas?
Its like my environment file is not getting picked up on forge.....
config/datasbase.php
<?php
return [
/*
|--------------------------------------------------------------------------
| PDO Fetch Style
|--------------------------------------------------------------------------
|
| By default, database results will be returned as instances of the PHP
| stdClass object; however, you may desire to retrieve records in an
| array format for simplicity. Here you can tweak the fetch style.
|
*/
'fetch' => PDO::FETCH_CLASS,
/*
|--------------------------------------------------------------------------
| Default Database Connection Name
|--------------------------------------------------------------------------
|
| Here you may specify which of the database connections below you wish
| to use as your default connection for all database work. Of course
| you may use many connections at once using the Database library.
|
*/
'default' => env('DB_CONNECTION', 'mysql'),
/*
|--------------------------------------------------------------------------
| Database Connections
|--------------------------------------------------------------------------
|
| Here are each of the database connections setup for your application.
| Of course, examples of configuring each database platform that is
| supported by Laravel is shown below to make development simple.
|
|
| All database work in Laravel is done through the PHP PDO facilities
| so make sure you have the driver for your particular database of
| choice installed on your machine before you begin development.
|
*/
'connections' => [
'sqlite' => [
'driver' => 'sqlite',
'database' => storage_path('database.sqlite'),
'prefix' => '',
],
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
],
'pgsql' => [
'driver' => 'pgsql',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'prefix' => '',
'schema' => 'public',
],
'sqlsrv' => [
'driver' => 'sqlsrv',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'prefix' => '',
],
],
/*
|--------------------------------------------------------------------------
| Migration Repository Table
|--------------------------------------------------------------------------
|
| This table keeps track of all the migrations that have already run for
| your application. Using this information, we can determine which of
| the migrations on disk haven't actually been run in the database.
|
*/
'migrations' => 'migrations',
/*
|--------------------------------------------------------------------------
| Redis Databases
|--------------------------------------------------------------------------
|
| Redis is an open source, fast, and advanced key-value store that also
| provides a richer set of commands than a typical key-value systems
| such as APC or Memcached. Laravel makes it easy to dig right in.
|
*/
'redis' => [
'cluster' => false,
'default' => [
'host' => '127.0.0.1',
'port' => 6379,
'database' => 0,
],
],
];
Upvotes: 2
Views: 7202
Reputation: 21
The reason this is happening is because forge is running the post install command on your project and your are probably accessing the database in one of your service providers to for may be a a variable you want to attach to your views, try commenting the code in the service provider, install the repository and then push the code up again it should work fine
Upvotes: 2
Reputation: 1654
try this
1
in app/database.php
Replace localhost with 127.0.0.1
'host'=> env('DB_HOST', 'localhost') -->'host' => env('DB_HOST', '127.0.0.1')
Also, in .env
DB_HOST=localhost --> DB_HOST=127.0.0.1
2
Try specify environment
php artisan migrate --env=local
3
Check to see if the MySQL is running by run
mysqladmin -u homestead -p status Enter password: secret
I got
Uptime: 21281 Threads: 3 Questions: 274 Slow queries: 0 Opens: 327 Flush tables: 1 Open tables: 80 Queries per second avg: 0.012
Which mean it's running.
4
Check MySQL UNIX Socket
5 make sure that your .env file looks something like this:
APP_ENV=local
APP_DEBUG=true
APP_KEY=YOURAPPKEY
DB_HOST=localhost
DB_DATABASE=YOURDBNAME
DB_USERNAME=YOURPHPMYADMINUSERNAME
DB_PASSWORD=YOURPHPMYADMINPASS
6
try changing localhost into 127.0.0.1 in .env DB_HOST or try add your mysql port
Upvotes: 1
Reputation: 417
The reason this was happening is because i was using the 'Install Repo' functionality that forge provides to install my full project. Now because there was no environment set on the server it was failing upon install.
To get around it, i had to hardcode the production database credentials, install the repo then create the env file. Then once this was done remove the hardcoded credentials (not great i know).
It seems setting the .env before the install doesn't work either. So you wouldn't run into this sort of issue if you had your repo installed on a server from the beginning of your build.
But my project is now live and running correctly. Thanks for the replies.
Upvotes: 1
Reputation: 277
It's hard to say anything for sure without seeing the .env file, but it looks like it's picking up the username from somewhere - the default is 'forge' and yet the error message has the username as an empty string - ''@localhost.
Check your env file, make sure there are no spaces after the = and that the variable names match the ones in the database config. I've also had issues where I needed to wrap passwords and other values that had special characters in ''. Finally, remember that case matters - I've seen problems where everything worked locally and failed on the dev server because someone had changed the case of a variable. My mac didn't care, but the ubuntu server did.
Upvotes: 0
Reputation: 1583
Make sure MySQL
user has all accessing privileges for given ip while connecting the MySQL
. For further reference please go through the below link.
http://tech2smooth.blogspot.in/2014/09/create-mysql-user-and-grant-permission.html
Upvotes: 0