laravel / framework

The Laravel Framework.
https://laravel.com
MIT License
32.23k stars 10.92k forks source link

Composer update fails without environment #725

Closed greggilbert closed 11 years ago

greggilbert commented 11 years ago

The php artisan optimize line in composer.json fails when the default database credentials are invalid.

The use case: I've got a 'development' environment set up and am just using that. Because I don't know the production credentials yet, I haven't put anything into /app/config/database.php. When I run composer update, it invokes php artisan optimize, which fails with PDOException: SQLSTATE[28000] [1045] Access denied for user 'root'@'localhost' (using password: NO) because the creds in the default database.php aren't correct. And it's not possible to call composer update with an environment variable set up, as far as I can see...

taylorotwell commented 11 years ago

I'm curious why you running optimize would even try to hit the database. Do you have some packages installed?

JoostK commented 11 years ago

Maybe we should look into a solution where optimize is only applied when on production, if that's possible.

I don't know about whether the optimized file is recompiled when dump-autoloads is run, or if artisan optimize will write a new one?

taylorotwell commented 11 years ago

Also, do you try to hit the database in a global script, like a start file or routes file?

taylorotwell commented 11 years ago

Then you must be trying to hit your database somewhere in a global script? Otherwise your database would never be called.

greggilbert commented 11 years ago

Sorry, I didn't actually answer the question. My start files and routes file are basically stock; I've added some routes in there, but none that explicitly use the database.

In terms of other packages, I've got the following:

        "laravelbook/laravel4-powerpack": "dev-master",
        "raveren/kint": "dev-master",
        "cartalyst/sentry": "2.0.*",
        "jasonlewis/basset": "dev-develop",
        "jasonlewis/expressive-date": "1.*",
        "bigelephant/presenter": "dev-master",
        "intervention/image": "dev-master"

Edit: I removed those and all of their providers, and still got the error.

greggilbert commented 11 years ago

I'm doing sessions in the database, so there was a migration generated around that. I wonder if this has to do with having the migration class?

greggilbert commented 11 years ago

Here's a dump of the error:

   1/1 PDOException: SQLSTATE[28000] [1045] Access denied for user 'root'@'localhost' (using password: NO)
    in /PROJECT/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php line 47
   at PDO->__construct('mysql:host=localhost;dbname=database', 'root', '', array('0', '2', '0', false, '0')) in /PROJECT/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php line 47
   at Connector->createConnection('mysql:host=localhost;dbname=database', array('driver' => 'mysql', 'host' => 'localhost', 'database' => 'database', 'username' => 'root', 'password' => '', 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => ''), array('0', '2', '0', false, '0')) in /PROJECT/vendor/laravel/framework/src/Illuminate/Database/Connectors/MySqlConnector.php line 20
   at MySqlConnector->connect(array('driver' => 'mysql', 'host' => 'localhost', 'database' => 'database', 'username' => 'root', 'password' => '', 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => '')) in /PROJECT/vendor/laravel/framework/src/Illuminate/Database/Connectors/ConnectionFactory.php line 25
   at ConnectionFactory->make(array('driver' => 'mysql', 'host' => 'localhost', 'database' => 'database', 'username' => 'root', 'password' => '', 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => ''), 'mysql') in /PROJECT/vendor/laravel/framework/src/Illuminate/Database/DatabaseManager.php line 87
   at DatabaseManager->makeConnection('mysql') in /PROJECT/vendor/laravel/framework/src/Illuminate/Database/DatabaseManager.php line 64
   at DatabaseManager->connection(null) in /PROJECT/vendor/laravel/framework/src/Illuminate/Session/SessionManager.php line 104
   at SessionManager->getDatabaseConnection() in /PROJECT/vendor/laravel/framework/src/Illuminate/Session/SessionManager.php line 88
   at SessionManager->createDatabaseDriver() in /PROJECT/vendor/laravel/framework/src/Illuminate/Support/Manager.php line 79
   at Manager->createDriver('database') in /PROJECT/vendor/laravel/framework/src/Illuminate/Support/Manager.php line 54
   at Manager->driver() in /PROJECT/vendor/laravel/framework/src/Illuminate/Session/SessionServiceProvider.php line 56
   at SessionServiceProvider->Illuminate\Session\{closure}(object(Application)) in /PROJECT/vendor/laravel/framework/src/Illuminate/Container/Container.php line 135
   at Container->Illuminate\Container\{closure}(object(Application), array()) in /PROJECT/vendor/laravel/framework/src/Illuminate/Container/Container.php line 291
   at Container->build(object(Closure), array()) in /PROJECT/vendor/laravel/framework/src/Illuminate/Container/Container.php line 236
   at Container->make('session', array()) in /PROJECT/vendor/laravel/framework/src/Illuminate/Foundation/Application.php line 377
   at Application->make('session') in /PROJECT/vendor/laravel/framework/src/Illuminate/Container/Container.php line 466
   at Container->offsetGet('session') in /PROJECT/vendor/laravel/framework/src/Illuminate/Session/SessionServiceProvider.php line 103
   at SessionServiceProvider->Illuminate\Session\{closure}(object(Application))
   at call_user_func(object(Closure), object(Application)) in /PROJECT/vendor/laravel/framework/src/Illuminate/Foundation/Application.php line 544
   at Application->fireAppCallbacks(array(object(Closure), object(Closure))) in /PROJECT/vendor/laravel/framework/src/Illuminate/Foundation/Application.php line 503
   at Application->boot() in /PROJECT/vendor/laravel/framework/src/Illuminate/Foundation/start.php line 194
   at require('/PROJECT/vendor/laravel/framework/src/Illuminate/Foundation/start.php') in /PROJECT/bootstrap/start.php line 58
   at require_once('/PROJECT/bootstrap/start.php') in /PROJECT/artisan line 30
taylorotwell commented 11 years ago

I think for Artisan tasks we probably just need to set the session driver to array in the framwork.

taylorotwell commented 11 years ago

Fixed. You may have to delete your vendor and composer.lock and composer install again.

geomagilles commented 11 years ago

I have an up-to-date L4 version, delete vendor and composer.lock and run composer install again - and still have the same problem with artisan using production environment :

php artisan optimize
{"error":{"type":"ErrorException","message":"Notice: Undefined index: DB1_HOST in \/Users\/Gilles\/Dropbox\/Sites\/l4\/app\/config\/production\/database.php line 9","file":"\/Users\/Gilles\/Dropbox\/Sites\/l4\/app\/config\/production\/database.php","line":9}}

My packages "require": { "laravel/framework": "4.0.", "cartalyst/sentry": "2.0.", "aws/aws-sdk-php": "2.2.*" }, Using "native" for sessions and "sync" vs "sqs" for queue in local vs production environment

Cosmicist commented 11 years ago

Same as @geomagilles here... I solve this by setting an environment variable on the CLI (in my .bashrc) and having this on my bootstrap/start.php file right below the regular $app->detectEnvoronment() call:

if ($app->runningInConsole() and getenv('LARAVEL_ENV')) {
    $env = $app['env'] = getenv('LARAVEL_ENV');
}

So I only have that env var set up in my production server. Hope it helps!

esveraldo commented 7 years ago

Thanks taylor otwell's tip, solved my problem here, old topic, but always current problems for those who are starting with this framework, thanks