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
php artisan serve and I navigate to http://localhost:8000/admin/categories/, I receive the following error message:
PDOException in Connector.php line 50: SQLSTATE[HY000]  No connection could be made because the target machine actively refused it.
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:
DB_HOST=localhost DB_DATABASE=homestead DB_USERNAME=homestead DB_PASSWORD=secret
And the mysql key within the database.php file is given as:
'mysql' => [ 'driver' => 'mysql', 'host' => env('DB_HOST', 'localhost'), 'database' => env('DB_DATABASE', 'homestead'), 'username' => env('DB_USERNAME', 'homestead'), 'password' => env('DB_PASSWORD', 'secret'), 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => '', 'strict' => false,
Oddly, when I ssh into my virtual machine and I run
mysql -uhomestead -psecret homestead, 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?