title: Laravel - mysql can't connect to server (111)
body: <p>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":</p>
  
  <blockquote>
    <p>[PDOException] SQL STATE[HY000] [2003] Can't connect to MySQL server on '162.243.167.251' (111)</p>
  </blockquote>
  
  <p>I have checked every forum on the internet trying to find the solution including:</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/1420839/cant-connect-to-mysql-server-error-111">Can't connect to MySQL server error 111 [closed]</a></li>
  <li><a href="https://stackoverflow.com/questions/38780631/cant-connect-to-mysql-server-111-even-after-changing-bind-address">Can't connect to MySQL server (111) even after changing bind-address</a></li>
  <li><a href="https://stackoverflow.com/questions/20334627/laravel-cant-connect-to-db">Laravel can't connect to DB</a></li>
  <li><a href="https://stackoverflow.com/questions/29326178/cant-connect-to-mysql-on-live-with-laravel-5">Can't connect to MySQL on live with Laravel 5</a></li>
  <li><a href="https://stackoverflow.com/questions/11758339/error-2003-hy000-cant-connect-to-mysql-server-111">ERROR 2003 (HY000): Can't connect to MySQL server (111)</a></li>
  </ul>
  
  <p><a href="https://i.stack.imgur.com/jQ06u.jpg" rel="nofollow noreferrer">I have connected to the database through my command line as seen here</a></p>
  
  <p>This is my .env setup:</p>
  
  <pre><code>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
  ...
  </code></pre>
  
  <p>And here is my config/database.php:</p>
  
  <pre><code>'mysql' =&gt; [
          'driver' =&gt; 'mysql',
          'host' =&gt; env('DB_HOST', 'localhost'),
          'port' =&gt; env('DB_PORT', '3306'),
          'database' =&gt; env('DB_DATABASE', 'foodb'),
          'username' =&gt; env('DB_USERNAME', 'foouser'),
          'password' =&gt; env('DB_PASSWORD', 'foopass'),
          'charset' =&gt; 'utf8',
          'collation' =&gt; 'utf8_unicode_ci',
          'prefix' =&gt; '',
          'strict' =&gt; false,
          'engine' =&gt; null,
      ],
  </code></pre>
  
  <p>I was wondering if my connections could be wrong or if I am missing something else.</p>