lando / laravel

The Official Laravel Lando Plugin
https://docs.lando.dev/laravel/
GNU General Public License v3.0
18 stars 11 forks source link

MySQL database connection refused but can access externally #4

Open anchetaWern opened 2 years ago

anchetaWern commented 2 years ago

I'm just trying out Lando for the first time using the Laravel recipe, but so far mysql is a headache. I can't seem to get it to work using this config:

name: my-lando-app
recipe: laravel
host: database
config:
  webroot: ./app/public
  via: nginx
  composer_version: '2.2.5'
  database: mysql:5.7

For context, I tried creating a database using the mysql on the host machine then exported it using table plus. Then I imported it to the lando app using lando db-import my_database.gz. I was able to connect to the database externally via tableplus by entering the following credentials:

But from within the app itself all I get is 'connection refused'. Here's my .env file:

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=laravel
DB_PASSWORD=laravel

There weren't any privileges attached to the database (not even sure if those comes along with exports). I checked the actual export file and all it has is CREATE, DROP, and INSERT calls so it's supposed to just work without me granting privileges or anything.

Any ideas what I might be missing?

sinnbeck commented 2 years ago

Your env is off :) https://docs.lando.dev/config/laravel.html#environment-file

DB_CONNECTION=mysql
DB_HOST=database //this as its inside docker
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=laravel
DB_PASSWORD=laravel

Also be aware that the root is /app on docker, so you have set your webroot to /app/app/public (unless laravel is in a subdirectory of course)


  webroot: ./public
anchetaWern commented 2 years ago

thanks! that worked. Will now try this out on an ubuntu and windows virtual machine so we could adapt lando for our team.

muhammadtalhaishtiaq commented 2 years ago

Your env is off :) https://docs.lando.dev/config/laravel.html#environment-file

DB_CONNECTION=mysql
DB_HOST=database //this as its inside docker
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=laravel
DB_PASSWORD=laravel

Also be aware that the root is /app on docker, so you have set your webroot to /app/app/public (unless laravel is in a subdirectory of course)

  webroot: ./public

Its not working for me, I have used this same method but getting error *`SQLSTATE[HY000] [2002] Connection refused (SQL: select from information_schema.tables where table_schema = laravel and table_name = migrations and table_type = 'BASE TABLE')`**

Please guide. Thanks

muhammadtalhaishtiaq commented 2 years ago

thanks! that worked. Will now try this out on an ubuntu and windows virtual machine so we could adapt lando for our team.

Could you please share your solution here for help. Thanks.

QasimMughal05 commented 11 months ago

I am on MAMP. I Just changed the port to 8889 and the password to root. It works php artisan config:cache php artisan cache:clear php artisan migrate