1

My laravel 5 application was working until I tried to put it on a live ubuntu server and then I ran into this error when running "php artisan migrate":

[PDOException] SQL STATE[HY000] [2003] Can't connect to MySQL server on '162.243.167.251' (111)

I have checked every forum on the internet trying to find the solution including:

I have connected to the database through my command line as seen here

This is my .env setup:

APP_ENV=local
APP_KEY=base64:9wh57LsV7Wnf0QVjr9KJE2Jw6Makot1wptoVW+O9Ky8=
APP_DEBUG=false
APP_LOG_LEVEL=debug
APP_URL=http://foo.com

DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=foodb
DB_USERNAME=foouser
DB_PASSWORD=foopass

CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_DRIVER=log
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
...

And here is my config/database.php:

'mysql' => [
        'driver' => 'mysql',
        'host' => env('DB_HOST', 'localhost'),
        'port' => env('DB_PORT', '3306'),
        'database' => env('DB_DATABASE', 'foodb'),
        'username' => env('DB_USERNAME', 'foouser'),
        'password' => env('DB_PASSWORD', 'foopass'),
        'charset' => 'utf8',
        'collation' => 'utf8_unicode_ci',
        'prefix' => '',
        'strict' => false,
        'engine' => null,
    ],

I was wondering if my connections could be wrong or if I am missing something else.

Community
  • 1
  • 1
Trey Burr
  • 11
  • 1
  • 2

1 Answers1

0

The error message is rather straightforward: your application can't establish a connection to the database with the settings you provided. It has nothing to do with your application, but rather with the configuration you gave. In other words, if you were to log in this server and do:

mysql -h localhost -P 3306 -u foouser -p foodb

And give the password, it would fail. This can be caused by several things:

  • One of the parameter you gave is wrong
  • You are trying to connect to the wrong server (the database is maybe on a remote server, no localhost?)
  • ...

It depends a lot on how is your server is configured so we can't help you much more than that.

Théo
  • 655
  • 7
  • 17
  • I tried doing your solution and I was able to log into mysql just fine. This is why my roommate and I have been stuck with this. – Trey Burr Aug 09 '16 at 00:27
  • did you try to log from the server where your application is deployed? If so it's possible that you have some cache issues but (i.e. your application would use old values) – Théo Aug 09 '16 at 16:11
  • I can log in on using the terminal on the host site just fine if that's what you're asking. I'm sorry not fully following. – Trey Burr Aug 09 '16 at 16:13
  • Yeah I meant running this command on the host file. Did you try to clear the cache just in case? – Théo Aug 09 '16 at 16:37
  • I just ran the command in the host and got in. I'm thinking it is a laravel issue. I removed my project and made a new laravel project, tested it and connected fine. But as soon as I ftp'd my files and replaced the default ones it threw the error. – Trey Burr Aug 09 '16 at 16:42
  • Did you try to dump your config on production (via Artisan for example) to see if it's what you expect? – Théo Aug 10 '16 at 03:51