Before going any further, I’ve been looking everywhere on how to run laravel sail’s project (including MySQL, Redis, etc) properly after cloning a repository without any local environments.
I have read some another questions and explanations, but still didn’t have any completed/proper answers.
- this answer only tell of how to have sail in that project
- this question has no answers until this question posted
- this one also only tell of how to have sail in that project
I have tried to create a new fresh laravel project by using sail, then upload to git, and clone it again to my local machine with using different folder, then tried all of above links.
- e.g For MySQL, I have tried to add
php artisan migrate
or runsail artisan migrate
and it showed connection refused. - I have tried to build first before run
sail up
- I have tried to copy env example file
Until now, I only can run the sail (I can access the webpage) but not the databases and so on.
Thank you.
2
Answers
Sometimes I have issues with existing volumes, those volumes exist but already have everything build. So even if i add a new project it still uses the incorrect volume.
please read below it explains it a lot better.
Laravel Sail rebuild default database
So what I normally do is use a proxy server on my local dev. so I can use different projects and can let them communicate together.
Edit:: the solution i used for local development
https://blog.devgenius.io/multi-laravel-sail-sites-with-custom-domain-e13c07d9dd0c
Reproducing the steps based on the information you provided this is what I did:
Note: I will assume you already have docker installed.
curl -s https://laravel.build/test-app | bash
sail up
(wait until the output stops) just to test it out, you cansail down
after:docker ps
if there is any container running (running container can cause issues if you don’t change Ports). If any container is running stop them withdocker container stop <name of container OR ID of container>
.env.example
to.env
. I changed where it has127.0.0.1
tolocalhost
. In theDB_HOST
change the value tomysql
./vendor/bin/sail/up
and the app will start. Open the app on the browser (localhost:80 if you didn’t change ports)../vendor/bin/sail artisan key:generate
./vendor/bin/sail artisan migrate
And you are good to go. Hope that it helps!