Change your database.php config to match the app.env file's details.
If you want to create a new database, you can access mysql in your VM with:
mysql -uhomestead -p
then enter the password secret when prompted.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I'm having trouble figuring out how to connect to databases. When I run 'php artisan migrate' or '$object->save()' form tinker, I get an error, most commonly: SQLSTATE[HY000] [2002] No connection could be made because the target machine actively refused it. If I SSH into homestead, then run 'mysql', I get: ERROR 1045 (28000): Access denied for user 'vagrant'@'localhost' (using password: NO)
My best guess is that it's a credentials issue or a port issue, but I haven't found the same situation online. I've been at this for two weeks, trying Laravel with XAMPP in Linux Mint, countless reinstallations of VirtualBox/Vagrant/Homestead, giving Laragon a try and starting on a different computer yet I still keep getting the same errors. So at this point I'm left wondering how much a framework needs to crush a beginner and what super obvious thing my little brain is missing. I turn to you in humble defeat.
This is how I setup my latest attempt on a second computer (Windows 7 64-bit):
vagrant box add laravel/homestead
composer global require "laravel/homestead=~2.0"
homestead init
ssh-keygen -t rsa -C "you@homestead"
composer global require "laravel/installer=~1.1"
laravel new laraduck in C:\dev\projectshomestead up
homestead ssh
serve laraduck.app /home/vagrant/dev/laraduck/public
$object->save(); in tinker doesn't work. php artisan migrate doesn't work. Running mysql in SSH gives me 'Access denied'.My homestead.yaml:
---
ip: "192.168.10.10"
memory: 2048
cpus: 1
provider: virtualbox
authorize: C:\Users\Coderooney\.ssh\id_rsa.pub
keys:
- C:\Users\Coderooney\.ssh\id_rsa
folders:
- map: C:\dev
to: /home/vagrant/dev
sites:
- map: laraduck.app
to: /home/vagrant/dev/projects/laraduck/public
databases:
- homestead
variables:
- key: APP_ENV
value: local
# blackfire:
# - id: foo
# token: bar
# client-id: foo
# client-token: bar
# ports:
# - send: 93000
# to: 9300
# - send: 7777
# to: 777
# protocol: udp
My database.php is untouched. 'mysql' section:
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
],
My .env is mostly untouched:
APP_ENV=local
APP_DEBUG=true
APP_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx //My actual .env has a real key
DB_HOST=127.0.0.1
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync
MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
Let me know what I can do to help you help me help you help me. Thank you so much.
I would suggest using the full LAN IP so you do it anywhere in the LAN network. That's what I do (192.168.10.10)
Please or to participate in this conversation.