title: PHP Laravel: No connection could be made because the target machine actively refused it
body: <p>I am building a web application in Laravel 5.  The application is supposed to get "category names" stored on a MySQL database and display a form to add new "category names".  When I execute the command <code>php artisan serve</code> and I navigate to <a href="http://localhost:8000/admin/categories/" rel="noreferrer">http://localhost:8000/admin/categories/</a>, I receive the following error message:</p>
  
  <pre><code>PDOException in Connector.php line 50:
  SQLSTATE[HY000] [2002] No connection could be made because the target machine actively refused it.
  </code></pre>
  
  <p>According to several posts I read on stack overflow, many users encountering this error did not properly configure the .env file, which overrides the default settings for the PHP Data Object (PDO), as specified in the database.php file.  The .env file is defined below:</p>
  
  <pre><code>DB_HOST=localhost
  DB_DATABASE=homestead
  DB_USERNAME=homestead
  DB_PASSWORD=secret
  </code></pre>
  
  <p>And the mysql key within the database.php file is given as:</p>
  
  <pre><code> 'mysql' =&gt; [
              'driver'    =&gt; 'mysql',
              'host'      =&gt; env('DB_HOST', 'localhost'),
              'database'  =&gt; env('DB_DATABASE', 'homestead'),
              'username'  =&gt; env('DB_USERNAME', 'homestead'),
              'password'  =&gt; env('DB_PASSWORD', 'secret'),
              'charset'   =&gt; 'utf8',
              'collation' =&gt; 'utf8_unicode_ci',
              'prefix'    =&gt; '',
              'strict'    =&gt; false,
  </code></pre>
  
  <p>Oddly, when I ssh into my virtual machine and I run <code>mysql -uhomestead -psecret homestead</code>, I am able to connect to the database.  The question is, why is Laravel unable to connect to MySQL when I can connect to it directly with the same parameters?  What else could be denying access to Laravel?</p>