简体   繁体   中英

Laravel 4.1 to Heroku: SQLSTATE[HY000] [2002] No such file or directory

I deployed my Laravel 4.1 app in Heroku by following this article http://phpartisan.tumblr.com/post/71580870739/running-laravel-4-on-heroku

The static HTML homepage loaded okay but when I am trying to log-in, I am getting the error

SQLSTATE[HY000] [2002] No such file or directory 

My local setup is Laravel 4.1 & MySQL.

I don't think there was a database created when I deployed.

Do I need to do it manually? How and what will be my settings then?

thanks!

The problem could be your environment might still point to local. in cli, type heroku run php artisan env to find out.

else, you might wanto run php artisan migrate --env=production to set it to the correct production environment.

you might then encounter another issue like this:

PHP Fatal error: Call to undefined function Symfony\\Component\\Console\\mb_convert_variables() in /var/www/mysite/vendor/symfony/console/Symfony/Component/Console/Application.php on line 1154

Trust me, tt has nothing to do with mb_string module like what this post stated. Laravel: Call to undefined function Symfony\\Component\\Console\\mb_convert_variables()?

The problem is at environment setting.

First, make sure you have .env.php file at same dir level with composer.json and it is exists in your heroku instance. Since you cant FTP inside, you need to push to repo. But laravel tell you this is git ignored, so you will need to temporary allow it to push to your heroku repo.

Next, you will need to edit the bootstrap\\start.php

replace the $env = $app->detectEnvironment(function(){}) to:

$env = $app->detectEnvironment(function() { return file_exists(dirname(__FILE__) . '/../.env.php') ? 'production' : 'local'; }); Once you done all these, rerun the migrate command and it will works.

You may follow this link for reference. Laravel environment config not loading, migration fails - SQLSTATE[HY000] [2002] No such file or directory

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM